summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-02-08 22:14:11 +0000
committerSanjay Patel <spatel@rotateright.com>2017-02-08 22:14:11 +0000
commita62bc44f6746d0cbcf9c0e1d71c5c32d6a203372 (patch)
tree3080b84186bd8f5787b67e1339c524f9e3f3ab2e /llvm/test/Transforms
parentc3a4b282bb787da8cb09d03b490df4aaadb81d33 (diff)
downloadbcm5719-llvm-a62bc44f6746d0cbcf9c0e1d71c5c32d6a203372.tar.gz
bcm5719-llvm-a62bc44f6746d0cbcf9c0e1d71c5c32d6a203372.zip
[InstCombine] add tests to show information-losing add nsw/nuw transforms; NFC
llvm-svn: 294524
Diffstat (limited to 'llvm/test/Transforms')
-rw-r--r--llvm/test/Transforms/InstCombine/add.ll43
-rw-r--r--llvm/test/Transforms/InstCombine/icmp-add.ll24
-rw-r--r--llvm/test/Transforms/InstCombine/sub-xor.ll10
3 files changed, 63 insertions, 14 deletions
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll
index 3ea78492470..03b2c3e8571 100644
--- a/llvm/test/Transforms/InstCombine/add.ll
+++ b/llvm/test/Transforms/InstCombine/add.ll
@@ -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) {
diff --git a/llvm/test/Transforms/InstCombine/icmp-add.ll b/llvm/test/Transforms/InstCombine/icmp-add.ll
index 3bf1849c91c..d00875f9a66 100644
--- a/llvm/test/Transforms/InstCombine/icmp-add.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-add.ll
@@ -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
+}
+
diff --git a/llvm/test/Transforms/InstCombine/sub-xor.ll b/llvm/test/Transforms/InstCombine/sub-xor.ll
index 9a0814c2c92..812305d8e48 100644
--- a/llvm/test/Transforms/InstCombine/sub-xor.ll
+++ b/llvm/test/Transforms/InstCombine/sub-xor.ll
@@ -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
-}
-
OpenPOWER on IntegriCloud