From 7cc56f1599b990afe806ad217352502c528a828d Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Thu, 26 Apr 2018 20:07:17 +0000 Subject: [PATCH] [InstCombine][NFC] add2.ll: add a few commutative checks. Fixes some missing test coverage in InstCombineAddSub.cpp, visitAdd() llvm-svn: 330986 --- llvm/test/Transforms/InstCombine/add2.ll | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/add2.ll b/llvm/test/Transforms/InstCombine/add2.ll index 6b2073c..ed99936 100644 --- a/llvm/test/Transforms/InstCombine/add2.ll +++ b/llvm/test/Transforms/InstCombine/add2.ll @@ -379,6 +379,39 @@ define i32 @add_or_and(i32 %x, i32 %y) { ret i32 %add } +define i32 @add_or_and_commutative(i32 %x, i32 %y) { +; CHECK-LABEL: @add_or_and_commutative( +; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret i32 [[ADD]] +; + %or = or i32 %x, %y + %and = and i32 %y, %x ; swapped + %add = add i32 %or, %and + ret i32 %add +} + +define i32 @add_and_or(i32 %x, i32 %y) { +; CHECK-LABEL: @add_and_or( +; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret i32 [[ADD]] +; + %or = or i32 %x, %y + %and = and i32 %x, %y + %add = add i32 %and, %or + ret i32 %add +} + +define i32 @add_and_or_commutative(i32 %x, i32 %y) { +; CHECK-LABEL: @add_and_or_commutative( +; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret i32 [[ADD]] +; + %or = or i32 %x, %y + %and = and i32 %y, %x ; swapped + %add = add i32 %and, %or + ret i32 %add +} + define i32 @add_nsw_or_and(i32 %x, i32 %y) { ; CHECK-LABEL: @add_nsw_or_and( ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[X:%.*]], [[Y:%.*]] -- 2.7.4