[InstCombine] add tests to show information-losing add nsw/nuw transforms; NFC
authorSanjay Patel <spatel@rotateright.com>
Wed, 8 Feb 2017 22:14:11 +0000 (22:14 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 8 Feb 2017 22:14:11 +0000 (22:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294524 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/InstCombine/add.ll
test/Transforms/InstCombine/icmp-add.ll
test/Transforms/InstCombine/sub-xor.ll

index 3ea78492470f67c734e36cdfa666f09f8a48672f..03b2c3e857120ad1797cb6e7ea74f0f82d47dfd9 100644 (file)
@@ -244,14 +244,49 @@ define i32 @test19(i1 %C) {
   ret i32 %V
 }
 
+; Add of sign bit -> xor of sign bit.
+
 define i32 @test20(i32 %x) {
 ; CHECK-LABEL: @test20(
 ; CHECK-NEXT:    ret i32 %x
 ;
-  %tmp.2 = xor i32 %x, -2147483648
-  ;; Add of sign bit -> xor of sign bit.
-  %tmp.4 = add i32 %tmp.2, -2147483648
-  ret i32 %tmp.4
+  %y = xor i32 %x, -2147483648
+  %z = add nsw i32 %y, -2147483648
+  ret i32 %z
+}
+
+define i32 @xor_sign_bit(i32 %x) {
+; CHECK-LABEL: @xor_sign_bit(
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 %x, -2147483606
+; CHECK-NEXT:    ret i32 [[ADD]]
+;
+  %xor = xor i32 %x, 2147483648
+  %add = add i32 %xor, 42
+  ret i32 %add
+}
+
+; Lose no-wrap info by converting to xor? %x is known non-negative
+; here, but not after converting to xor.
+
+define i8 @add_nsw_signbit(i8 %x) {
+; CHECK-LABEL: @add_nsw_signbit(
+; CHECK-NEXT:    [[Y:%.*]] = xor i8 %x, -128
+; CHECK-NEXT:    ret i8 [[Y]]
+;
+  %y = add nsw i8 %x, -128
+  ret i8 %y
+}
+
+; Lose no-wrap info by converting to xor? %x is known non-negative
+; (x < 128 unsigned), but not after converting to xor.
+
+define i8 @add_nuw_signbit(i8 %x) {
+; CHECK-LABEL: @add_nuw_signbit(
+; CHECK-NEXT:    [[Y:%.*]] = xor i8 %x, -128
+; CHECK-NEXT:    ret i8 [[Y]]
+;
+  %y = add nuw i8 %x, 128
+  ret i8 %y
 }
 
 define i1 @test21(i32 %x) {
index 3bf1849c91c96bf180df1837568bd2a41e972e1d..d00875f9a66224fdd075737dbf209a6e81088d00 100644 (file)
@@ -106,3 +106,27 @@ define <2 x i1> @slt_zero_add_nsw_splat_vec(<2 x i8> %a) {
   ret <2 x i1> %cmp
 }
 
+; FIXME: InstCombine should not lose wrapping information by changing the add to xor.
+
+define i1 @slt_zero_add_nsw_signbit(i8 %x) {
+; CHECK-LABEL: @slt_zero_add_nsw_signbit(
+; CHECK-NEXT:    [[Z:%.*]] = icmp sgt i8 %x, -1
+; CHECK-NEXT:    ret i1 [[Z]]
+;
+  %y = add nsw i8 %x, -128
+  %z = icmp slt i8 %y, 0
+  ret i1 %z
+}
+
+; FIXME: InstCombine should not lose wrapping information by changing the add to xor.
+
+define i1 @slt_zero_add_nuw_signbit(i8 %x) {
+; CHECK-LABEL: @slt_zero_add_nuw_signbit(
+; CHECK-NEXT:    [[Z:%.*]] = icmp sgt i8 %x, -1
+; CHECK-NEXT:    ret i1 [[Z]]
+;
+  %y = add nuw i8 %x, 128
+  %z = icmp slt i8 %y, 0
+  ret i1 %z
+}
+
index 9a0814c2c92f8c3528f9a46be18172f9e618efaa..812305d8e4896870c34744558e2a4f977fe9fadf 100644 (file)
@@ -48,13 +48,3 @@ define i32 @test3(i32 %x) {
   ret i32 %add
 }
 
-define i32 @test4(i32 %x) {
-; CHECK-LABEL: @test4(
-; CHECK-NEXT:    [[ADD:%.*]] = add i32 %x, -2147483606
-; CHECK-NEXT:    ret i32 [[ADD]]
-;
-  %sub = xor i32 %x, 2147483648
-  %add = add i32 %sub, 42
-  ret i32 %add
-}
-