From: Sanjay Patel Date: Tue, 14 Mar 2017 16:27:46 +0000 (+0000) Subject: [InstCombine] consolidate rem tests and update checks; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=acccef0ba4fd98c879b98079076684a2a75cfdc2;p=llvm [InstCombine] consolidate rem tests and update checks; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297747 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll b/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll deleted file mode 100644 index 0c0e55a0b2d..00000000000 --- a/test/Transforms/InstCombine/2008-11-20-DivMulRem.ll +++ /dev/null @@ -1,67 +0,0 @@ -; RUN: opt < %s -instcombine -S | FileCheck %s -; PR3103 - -define i8 @test1(i8 %x, i8 %y) { -; CHECK-LABEL: @test1( - %A = udiv i8 %x, %y -; CHECK-NEXT: urem - %B = mul i8 %A, %y - %C = sub i8 %x, %B - ret i8 %C -; CHECK-NEXT: ret -} - -define i8 @test2(i8 %x, i8 %y) { -; CHECK-LABEL: @test2( - %A = sdiv i8 %x, %y -; CHECK-NEXT: srem - %B = mul i8 %A, %y - %C = sub i8 %x, %B - ret i8 %C -; CHECK-NEXT: ret -} - -define i8 @test3(i8 %x, i8 %y) { -; CHECK-LABEL: @test3( - %A = udiv i8 %x, %y -; CHECK-NEXT: urem - %B = mul i8 %A, %y - %C = sub i8 %B, %x -; CHECK-NEXT: sub - ret i8 %C -; CHECK-NEXT: ret -} - -define i8 @test4(i8 %x) { -; CHECK-LABEL: @test4( - %A = udiv i8 %x, 3 -; CHECK-NEXT: urem - %B = mul i8 %A, -3 -; CHECK-NEXT: sub - %C = sub i8 %x, %B -; CHECK-NEXT: add - ret i8 %C -; CHECK-NEXT: ret -} - -define i32 @test5(i32 %x, i32 %y) { -; CHECK-LABEL: @test5( -; (((X / Y) * Y) / Y) -> X / Y - %div = sdiv i32 %x, %y -; CHECK-NEXT: sdiv - %mul = mul i32 %div, %y - %r = sdiv i32 %mul, %y - ret i32 %r -; CHECK-NEXT: ret -} - -define i32 @test6(i32 %x, i32 %y) { -; CHECK-LABEL: @test6( -; (((X / Y) * Y) / Y) -> X / Y - %div = udiv i32 %x, %y -; CHECK-NEXT: udiv - %mul = mul i32 %div, %y - %r = udiv i32 %mul, %y - ret i32 %r -; CHECK-NEXT: ret -} diff --git a/test/Transforms/InstCombine/rem.ll b/test/Transforms/InstCombine/rem.ll index 7385341391e..75ac27c9c85 100644 --- a/test/Transforms/InstCombine/rem.ll +++ b/test/Transforms/InstCombine/rem.ll @@ -1,5 +1,147 @@ ; RUN: opt < %s -instcombine -S | FileCheck %s +define i64 @rem_signed(i64 %x1, i64 %y2) { +; CHECK-LABEL: @rem_signed( +; CHECK-NEXT: [[R:%.*]] = srem i64 %x1, %y2 +; CHECK-NEXT: ret i64 [[R]] +; + %r = sdiv i64 %x1, %y2 + %r7 = mul i64 %r, %y2 + %r8 = sub i64 %x1, %r7 + ret i64 %r8 +} + +define <4 x i32> @rem_signed_vec(<4 x i32> %t, <4 x i32> %u) { +; CHECK-LABEL: @rem_signed_vec( +; CHECK-NEXT: [[K:%.*]] = srem <4 x i32> %t, %u +; CHECK-NEXT: ret <4 x i32> [[K]] +; + %k = sdiv <4 x i32> %t, %u + %l = mul <4 x i32> %k, %u + %m = sub <4 x i32> %t, %l + ret <4 x i32> %m +} + +define i64 @rem_unsigned(i64 %x1, i64 %y2) { +; CHECK-LABEL: @rem_unsigned( +; CHECK-NEXT: [[R:%.*]] = urem i64 %x1, %y2 +; CHECK-NEXT: ret i64 [[R]] +; + %r = udiv i64 %x1, %y2 + %r7 = mul i64 %r, %y2 + %r8 = sub i64 %x1, %r7 + ret i64 %r8 +} + +; PR28672 - https://llvm.org/bugs/show_bug.cgi?id=28672 + +define i8 @big_divisor(i8 %x) { +; CHECK-LABEL: @big_divisor( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 %x, -127 +; CHECK-NEXT: [[TMP2:%.*]] = add i8 %x, 127 +; CHECK-NEXT: [[REM:%.*]] = select i1 [[TMP1]], i8 %x, i8 [[TMP2]] +; CHECK-NEXT: ret i8 [[REM]] +; + %rem = urem i8 %x, 129 + ret i8 %rem +} + +define i5 @biggest_divisor(i5 %x) { +; CHECK-LABEL: @biggest_divisor( +; CHECK-NEXT: [[NOT_:%.*]] = icmp eq i5 %x, -1 +; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[NOT_]] to i5 +; CHECK-NEXT: [[REM:%.*]] = add i5 [[TMP1]], %x +; CHECK-NEXT: ret i5 [[REM]] +; + %rem = urem i5 %x, -1 + ret i5 %rem +} + +; TODO: Should vector subtract of constant be canonicalized to add? +define <2 x i4> @big_divisor_vec(<2 x i4> %x) { +; CHECK-LABEL: @big_divisor_vec( +; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <2 x i4> %x, +; CHECK-NEXT: [[TMP2:%.*]] = sub <2 x i4> %x, +; CHECK-NEXT: [[REM:%.*]] = select <2 x i1> [[TMP1]], <2 x i4> %x, <2 x i4> [[TMP2]] +; CHECK-NEXT: ret <2 x i4> [[REM]] +; + %rem = urem <2 x i4> %x, + ret <2 x i4> %rem +} + +define i8 @urem1(i8 %x, i8 %y) { +; CHECK-LABEL: @urem1( +; CHECK-NEXT: [[A:%.*]] = urem i8 %x, %y +; CHECK-NEXT: ret i8 [[A]] +; + %A = udiv i8 %x, %y + %B = mul i8 %A, %y + %C = sub i8 %x, %B + ret i8 %C +} + +define i8 @srem1(i8 %x, i8 %y) { +; CHECK-LABEL: @srem1( +; CHECK-NEXT: [[A:%.*]] = srem i8 %x, %y +; CHECK-NEXT: ret i8 [[A]] +; + %A = sdiv i8 %x, %y + %B = mul i8 %A, %y + %C = sub i8 %x, %B + ret i8 %C +} + +define i8 @urem2(i8 %x, i8 %y) { +; CHECK-LABEL: @urem2( +; CHECK-NEXT: [[A:%.*]] = urem i8 %x, %y +; CHECK-NEXT: [[C:%.*]] = sub i8 0, [[A]] +; CHECK-NEXT: ret i8 [[C]] +; + %A = udiv i8 %x, %y + %B = mul i8 %A, %y + %C = sub i8 %B, %x + ret i8 %C +} + +define i8 @urem3(i8 %x) { +; CHECK-LABEL: @urem3( +; CHECK-NEXT: [[A:%.*]] = urem i8 %x, 3 +; CHECK-NEXT: [[B1:%.*]] = sub i8 %x, [[A]] +; CHECK-NEXT: [[C:%.*]] = add i8 [[B1]], %x +; CHECK-NEXT: ret i8 [[C]] +; + %A = udiv i8 %x, 3 + %B = mul i8 %A, -3 + %C = sub i8 %x, %B + ret i8 %C +} + +; (((X / Y) * Y) / Y) -> X / Y + +define i32 @sdiv_mul_sdiv(i32 %x, i32 %y) { +; CHECK-LABEL: @sdiv_mul_sdiv( +; CHECK-NEXT: [[R:%.*]] = sdiv i32 %x, %y +; CHECK-NEXT: ret i32 [[R]] +; + %div = sdiv i32 %x, %y + %mul = mul i32 %div, %y + %r = sdiv i32 %mul, %y + ret i32 %r +} + +; (((X / Y) * Y) / Y) -> X / Y + +define i32 @udiv_mul_udiv(i32 %x, i32 %y) { +; CHECK-LABEL: @udiv_mul_udiv( +; CHECK-NEXT: [[R:%.*]] = udiv i32 %x, %y +; CHECK-NEXT: ret i32 [[R]] +; + %div = udiv i32 %x, %y + %mul = mul i32 %div, %y + %r = udiv i32 %mul, %y + ret i32 %r +} + define i32 @test1(i32 %A) { ; CHECK-LABEL: @test1( ; CHECK-NEXT: ret i32 0 @@ -429,3 +571,4 @@ rem.is.safe: rem.is.unsafe: ret i32 0 } + diff --git a/test/Transforms/InstCombine/srem.ll b/test/Transforms/InstCombine/srem.ll deleted file mode 100644 index beefe4fb8d3..00000000000 --- a/test/Transforms/InstCombine/srem.ll +++ /dev/null @@ -1,8 +0,0 @@ -; RUN: opt < %s -instcombine -S | grep srem - -define i64 @foo(i64 %x1, i64 %y2) { - %r = sdiv i64 %x1, %y2 - %r7 = mul i64 %r, %y2 - %r8 = sub i64 %x1, %r7 - ret i64 %r8 -} diff --git a/test/Transforms/InstCombine/urem.ll b/test/Transforms/InstCombine/urem.ll deleted file mode 100644 index 0549d759eac..00000000000 --- a/test/Transforms/InstCombine/urem.ll +++ /dev/null @@ -1,50 +0,0 @@ -; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt < %s -instcombine -S | FileCheck %s - -define i64 @rem_unsigned(i64 %x1, i64 %y2) { -; CHECK-LABEL: @rem_unsigned( -; CHECK-NEXT: [[R:%.*]] = urem i64 %x1, %y2 -; CHECK-NEXT: ret i64 [[R]] -; - %r = udiv i64 %x1, %y2 - %r7 = mul i64 %r, %y2 - %r8 = sub i64 %x1, %r7 - ret i64 %r8 -} - -; PR28672 - https://llvm.org/bugs/show_bug.cgi?id=28672 - -define i8 @big_divisor(i8 %x) { -; CHECK-LABEL: @big_divisor( -; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 %x, -127 -; CHECK-NEXT: [[TMP2:%.*]] = add i8 %x, 127 -; CHECK-NEXT: [[REM:%.*]] = select i1 [[TMP1]], i8 %x, i8 [[TMP2]] -; CHECK-NEXT: ret i8 [[REM]] -; - %rem = urem i8 %x, 129 - ret i8 %rem -} - -define i5 @biggest_divisor(i5 %x) { -; CHECK-LABEL: @biggest_divisor( -; CHECK-NEXT: [[NOT_:%.*]] = icmp eq i5 %x, -1 -; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[NOT_]] to i5 -; CHECK-NEXT: [[REM:%.*]] = add i5 [[TMP1]], %x -; CHECK-NEXT: ret i5 [[REM]] -; - %rem = urem i5 %x, -1 - ret i5 %rem -} - -; TODO: Should vector subtract of constant be canonicalized to add? -define <2 x i4> @big_divisor_vec(<2 x i4> %x) { -; CHECK-LABEL: @big_divisor_vec( -; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <2 x i4> %x, -; CHECK-NEXT: [[TMP2:%.*]] = sub <2 x i4> %x, -; CHECK-NEXT: [[REM:%.*]] = select <2 x i1> [[TMP1]], <2 x i4> %x, <2 x i4> [[TMP2]] -; CHECK-NEXT: ret <2 x i4> [[REM]] -; - %rem = urem <2 x i4> %x, - ret <2 x i4> %rem -} - diff --git a/test/Transforms/InstCombine/vector-srem.ll b/test/Transforms/InstCombine/vector-srem.ll deleted file mode 100644 index 44b38596e68..00000000000 --- a/test/Transforms/InstCombine/vector-srem.ll +++ /dev/null @@ -1,13 +0,0 @@ -; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt < %s -instcombine -S | FileCheck %s - -define <4 x i32> @foo(<4 x i32> %t, <4 x i32> %u) { -; CHECK-LABEL: @foo( -; CHECK-NEXT: [[K:%.*]] = srem <4 x i32> %t, %u -; CHECK-NEXT: ret <4 x i32> [[K]] -; - %k = sdiv <4 x i32> %t, %u - %l = mul <4 x i32> %k, %u - %m = sub <4 x i32> %t, %l - ret <4 x i32> %m -}