summaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine/and2.ll
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/InstCombine/and2.ll')
-rw-r--r--test/Transforms/InstCombine/and2.ll87
1 files changed, 72 insertions, 15 deletions
diff --git a/test/Transforms/InstCombine/and2.ll b/test/Transforms/InstCombine/and2.ll
index 3d043b0864cd..001ac58891e4 100644
--- a/test/Transforms/InstCombine/and2.ll
+++ b/test/Transforms/InstCombine/and2.ll
@@ -45,21 +45,6 @@ define <4 x i32> @test5(<4 x i32> %A) {
ret <4 x i32> %2
}
-; Check that we combine "if x!=0 && x!=-1" into "if x+1u>1"
-define i32 @test6(i64 %x) nounwind {
-; CHECK-LABEL: @test6(
-; CHECK-NEXT: [[X_OFF:%.*]] = add i64 %x, 1
-; CHECK-NEXT: [[X_CMP:%.*]] = icmp ugt i64 [[X_OFF]], 1
-; CHECK-NEXT: [[LAND_EXT:%.*]] = zext i1 [[X_CMP]] to i32
-; CHECK-NEXT: ret i32 [[LAND_EXT]]
-;
- %cmp1 = icmp ne i64 %x, -1
- %not.cmp = icmp ne i64 %x, 0
- %.cmp1 = and i1 %cmp1, %not.cmp
- %land.ext = zext i1 %.cmp1 to i32
- ret i32 %land.ext
-}
-
define i1 @test7(i32 %i, i1 %b) {
; CHECK-LABEL: @test7(
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 %i, 0
@@ -110,6 +95,18 @@ define i64 @test9(i64 %x) {
ret i64 %and
}
+; combine -x & 1 into x & 1
+define <2 x i64> @test9vec(<2 x i64> %x) {
+; CHECK-LABEL: @test9vec(
+; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i64> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i64> [[SUB]], <i64 1, i64 1>
+; CHECK-NEXT: ret <2 x i64> [[AND]]
+;
+ %sub = sub nsw <2 x i64> <i64 0, i64 0>, %x
+ %and = and <2 x i64> %sub, <i64 1, i64 1>
+ ret <2 x i64> %and
+}
+
define i64 @test10(i64 %x) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: [[AND:%.*]] = and i64 %x, 1
@@ -122,3 +119,63 @@ define i64 @test10(i64 %x) {
ret i64 %add
}
+; The add in this test is unnecessary because the LSBs of the LHS are 0 and the 'and' only consumes bits from those LSBs. It doesn't matter what happens to the upper bits.
+define i32 @test11(i32 %a, i32 %b) {
+; CHECK-LABEL: @test11(
+; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
+; CHECK-NEXT: [[Z:%.*]] = and i32 [[B:%.*]], 128
+; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
+; CHECK-NEXT: ret i32 [[W]]
+;
+ %x = shl i32 %a, 8
+ %y = add i32 %x, %b
+ %z = and i32 %y, 128
+ %w = mul i32 %z, %x ; to keep the shift from being removed
+ ret i32 %w
+}
+
+; The add in this test is unnecessary because the LSBs of the RHS are 0 and the 'and' only consumes bits from those LSBs. It doesn't matter what happens to the upper bits.
+define i32 @test12(i32 %a, i32 %b) {
+; CHECK-LABEL: @test12(
+; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
+; CHECK-NEXT: [[Z:%.*]] = and i32 [[B:%.*]], 128
+; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
+; CHECK-NEXT: ret i32 [[W]]
+;
+ %x = shl i32 %a, 8
+ %y = add i32 %b, %x
+ %z = and i32 %y, 128
+ %w = mul i32 %z, %x ; to keep the shift from being removed
+ ret i32 %w
+}
+
+; The sub in this test is unnecessary because the LSBs of the RHS are 0 and the 'and' only consumes bits from those LSBs. It doesn't matter what happens to the upper bits.
+define i32 @test13(i32 %a, i32 %b) {
+; CHECK-LABEL: @test13(
+; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
+; CHECK-NEXT: [[Z:%.*]] = and i32 [[B:%.*]], 128
+; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
+; CHECK-NEXT: ret i32 [[W]]
+;
+ %x = shl i32 %a, 8
+ %y = sub i32 %b, %x
+ %z = and i32 %y, 128
+ %w = mul i32 %z, %x ; to keep the shift from being removed
+ ret i32 %w
+}
+
+; The sub in this test cannot be removed because we need to keep the negation of %b. TODO: But we should be able to replace the LHS of it with a 0.
+define i32 @test14(i32 %a, i32 %b) {
+; CHECK-LABEL: @test14(
+; CHECK-NEXT: [[X:%.*]] = shl i32 [[A:%.*]], 8
+; CHECK-NEXT: [[Y:%.*]] = sub i32 0, [[B:%.*]]
+; CHECK-NEXT: [[Z:%.*]] = and i32 [[Y]], 128
+; CHECK-NEXT: [[W:%.*]] = mul i32 [[Z]], [[X]]
+; CHECK-NEXT: ret i32 [[W]]
+;
+ %x = shl i32 %a, 8
+ %y = sub i32 %x, %b
+ %z = and i32 %y, 128
+ %w = mul i32 %z, %x ; to keep the shift from being removed
+ ret i32 %w
+}