From 3d7b22621c8c06d0f7f49837173359529c55a306 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Thu, 26 Apr 2018 18:44:37 +0000 Subject: [PATCH] [NFC][InstCombine] rem.ll: add a few commutative tests. This closes a gap in missing test coverage in isKnownToBeAPowerOfTwo() from ValueTracking.cpp llvm-svn: 330975 --- llvm/test/Transforms/InstCombine/rem.ll | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/rem.ll b/llvm/test/Transforms/InstCombine/rem.ll index 0a27e84..d4f1a79 100644 --- a/llvm/test/Transforms/InstCombine/rem.ll +++ b/llvm/test/Transforms/InstCombine/rem.ll @@ -386,6 +386,60 @@ define i32 @test19(i32 %x, i32 %y) { ret i32 %E } +define i32 @test19_commutative0(i32 %x, i32 %y) { +; CHECK-LABEL: @test19_commutative0( +; CHECK-NEXT: [[A:%.*]] = shl i32 1, [[X:%.*]] +; CHECK-NEXT: [[B:%.*]] = shl i32 1, [[Y:%.*]] +; CHECK-NEXT: [[C:%.*]] = and i32 [[B]], [[A]] +; CHECK-NEXT: [[D:%.*]] = add i32 [[C]], [[A]] +; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[D]], -1 +; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[Y]] +; CHECK-NEXT: ret i32 [[E]] +; + %A = shl i32 1, %x + %B = shl i32 1, %y + %C = and i32 %B, %A ; swapped + %D = add i32 %C, %A + %E = urem i32 %y, %D + ret i32 %E +} + +define i32 @test19_commutative1(i32 %x, i32 %y) { +; CHECK-LABEL: @test19_commutative1( +; CHECK-NEXT: [[A:%.*]] = shl i32 1, [[X:%.*]] +; CHECK-NEXT: [[B:%.*]] = shl i32 1, [[Y:%.*]] +; CHECK-NEXT: [[C:%.*]] = and i32 [[A]], [[B]] +; CHECK-NEXT: [[D:%.*]] = add i32 [[A]], [[C]] +; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[D]], -1 +; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[Y]] +; CHECK-NEXT: ret i32 [[E]] +; + %A = shl i32 1, %x + %B = shl i32 1, %y + %C = and i32 %A, %B + %D = add i32 %A, %C ; swapped + %E = urem i32 %y, %D + ret i32 %E +} + +define i32 @test19_commutative2(i32 %x, i32 %y) { +; CHECK-LABEL: @test19_commutative2( +; CHECK-NEXT: [[A:%.*]] = shl i32 1, [[X:%.*]] +; CHECK-NEXT: [[B:%.*]] = shl i32 1, [[Y:%.*]] +; CHECK-NEXT: [[C:%.*]] = and i32 [[B]], [[A]] +; CHECK-NEXT: [[D:%.*]] = add i32 [[A]], [[C]] +; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[D]], -1 +; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[Y]] +; CHECK-NEXT: ret i32 [[E]] +; + %A = shl i32 1, %x + %B = shl i32 1, %y + %C = and i32 %B, %A ; swapped + %D = add i32 %A, %C ; swapped + %E = urem i32 %y, %D + ret i32 %E +} + define <2 x i64> @test20(<2 x i64> %X, <2 x i1> %C) { ; CHECK-LABEL: @test20( ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i64> , <2 x i64> zeroinitializer -- 2.7.4