aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/InstCombine')
-rw-r--r--test/Transforms/InstCombine/cast-malloc.ll15
-rw-r--r--test/Transforms/InstCombine/cast.ll4
-rw-r--r--test/Transforms/InstCombine/compare-signs.ll1
-rw-r--r--test/Transforms/InstCombine/crash.ll12
-rw-r--r--test/Transforms/InstCombine/getelementptr.ll2
-rw-r--r--test/Transforms/InstCombine/intrinsics.ll73
-rw-r--r--test/Transforms/InstCombine/or.ll44
-rw-r--r--test/Transforms/InstCombine/or2.ll12
-rw-r--r--test/Transforms/InstCombine/phi-merge.ll31
-rw-r--r--test/Transforms/InstCombine/shufflevec-constant.ll2
-rw-r--r--test/Transforms/InstCombine/store-merge.ll37
-rw-r--r--test/Transforms/InstCombine/store.ll1
12 files changed, 130 insertions, 104 deletions
diff --git a/test/Transforms/InstCombine/cast-malloc.ll b/test/Transforms/InstCombine/cast-malloc.ll
deleted file mode 100644
index 3754032cc2f7..000000000000
--- a/test/Transforms/InstCombine/cast-malloc.ll
+++ /dev/null
@@ -1,15 +0,0 @@
-; test that casted mallocs get converted to malloc of the right type
-; RUN: opt < %s -instcombine -S | \
-; RUN: not grep bitcast
-
-; The target datalayout is important for this test case. We have to tell
-; instcombine that the ABI alignment for a long is 4-bytes, not 8, otherwise
-; it won't do the transform.
-target datalayout = "e-i64:32:64"
-
-define i32* @test(i32 %size) {
- %X = malloc i64, i32 %size ; <i64*> [#uses=1]
- %ret = bitcast i64* %X to i32* ; <i32*> [#uses=1]
- ret i32* %ret
-}
-
diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll
index e7695b74b75e..5f75cd0a8930 100644
--- a/test/Transforms/InstCombine/cast.ll
+++ b/test/Transforms/InstCombine/cast.ll
@@ -103,7 +103,7 @@ define i32* @test12() {
%p = malloc [4 x i8] ; <[4 x i8]*> [#uses=1]
%c = bitcast [4 x i8]* %p to i32* ; <i32*> [#uses=1]
ret i32* %c
-; CHECK: %malloccall = tail call i8* @malloc(i32 ptrtoint ([4 x i8]* getelementptr ([4 x i8]* null, i32 1) to i32))
+; CHECK: %malloccall = tail call i8* @malloc(i32 4)
; CHECK: ret i32* %c
}
@@ -275,7 +275,7 @@ define void @test32(double** %tmp) {
%tmp8.upgrd.1 = bitcast [16 x i8]* %tmp8 to double* ; <double*> [#uses=1]
store double* %tmp8.upgrd.1, double** %tmp
ret void
-; CHECK: %malloccall = tail call i8* @malloc(i32 ptrtoint ([16 x i8]* getelementptr ([16 x i8]* null, i32 1) to i32))
+; CHECK: %malloccall = tail call i8* @malloc(i32 16)
; CHECK: %tmp8.upgrd.1 = bitcast i8* %malloccall to double*
; CHECK: store double* %tmp8.upgrd.1, double** %tmp
; CHECK: ret void
diff --git a/test/Transforms/InstCombine/compare-signs.ll b/test/Transforms/InstCombine/compare-signs.ll
index 2f98641a2494..ba638ba36fc0 100644
--- a/test/Transforms/InstCombine/compare-signs.ll
+++ b/test/Transforms/InstCombine/compare-signs.ll
@@ -1,5 +1,4 @@
; RUN: opt %s -instcombine -S | FileCheck %s
-; XFAIL: *
; PR5438
; TODO: This should also optimize down.
diff --git a/test/Transforms/InstCombine/crash.ll b/test/Transforms/InstCombine/crash.ll
index fbac472e1972..1528f6ddf3c0 100644
--- a/test/Transforms/InstCombine/crash.ll
+++ b/test/Transforms/InstCombine/crash.ll
@@ -125,3 +125,15 @@ l10:
%v11 = select i1 %v5_, i64 0, i64 %v6
ret i64 %v11
}
+
+; PR5471
+define arm_apcscc i32 @test5a() {
+ ret i32 0
+}
+
+define arm_apcscc void @test5() {
+ store i1 true, i1* undef
+ %1 = invoke i32 @test5a() to label %exit unwind label %exit
+exit:
+ ret void
+}
diff --git a/test/Transforms/InstCombine/getelementptr.ll b/test/Transforms/InstCombine/getelementptr.ll
index 285e0ba602f4..de325f64021f 100644
--- a/test/Transforms/InstCombine/getelementptr.ll
+++ b/test/Transforms/InstCombine/getelementptr.ll
@@ -445,7 +445,7 @@ define i32 @test35() nounwind {
i8* getelementptr (%t1* bitcast (%t0* @s to %t1*), i32 0, i32 1, i32 0)) nounwind
ret i32 0
; CHECK: @test35
-; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* bitcast (i8** getelementptr (%t1* bitcast (%t0* @s to %t1*), i64 1, i32 0) to i8*)) nounwind
+; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i64 0, i64 0), i8* getelementptr inbounds (%t0* @s, i64 0, i32 1, i64 0)) nounwind
}
; Instcombine should constant-fold the GEP so that indices that have
diff --git a/test/Transforms/InstCombine/intrinsics.ll b/test/Transforms/InstCombine/intrinsics.ll
index 7abd38040136..fda4386e9439 100644
--- a/test/Transforms/InstCombine/intrinsics.ll
+++ b/test/Transforms/InstCombine/intrinsics.ll
@@ -1,12 +1,79 @@
; RUN: opt %s -instcombine -S | FileCheck %s
-declare {i8, i1} @llvm.uadd.with.overflow.i8(i8, i8)
+%overflow.result = type {i8, i1}
+
+declare %overflow.result @llvm.uadd.with.overflow.i8(i8, i8)
+declare %overflow.result @llvm.umul.with.overflow.i8(i8, i8)
define i8 @test1(i8 %A, i8 %B) {
- %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %A, i8 %B)
- %y = extractvalue {i8, i1} %x, 0
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 %B)
+ %y = extractvalue %overflow.result %x, 0
ret i8 %y
; CHECK: @test1
; CHECK-NEXT: %y = add i8 %A, %B
; CHECK-NEXT: ret i8 %y
}
+
+define i8 @test2(i8 %A, i8 %B, i1* %overflowPtr) {
+ %and.A = and i8 %A, 127
+ %and.B = and i8 %B, 127
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %and.A, i8 %and.B)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @test2
+; CHECK-NEXT: %and.A = and i8 %A, 127
+; CHECK-NEXT: %and.B = and i8 %B, 127
+; CHECK-NEXT: %1 = add nuw i8 %and.A, %and.B
+; CHECK-NEXT: store i1 false, i1* %overflowPtr
+; CHECK-NEXT: ret i8 %1
+}
+
+define i8 @test3(i8 %A, i8 %B, i1* %overflowPtr) {
+ %or.A = or i8 %A, -128
+ %or.B = or i8 %B, -128
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %or.A, i8 %or.B)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @test3
+; CHECK-NEXT: %or.A = or i8 %A, -128
+; CHECK-NEXT: %or.B = or i8 %B, -128
+; CHECK-NEXT: %1 = add i8 %or.A, %or.B
+; CHECK-NEXT: store i1 true, i1* %overflowPtr
+; CHECK-NEXT: ret i8 %1
+}
+
+define i8 @test4(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 undef, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @test4
+; CHECK-NEXT: ret i8 undef
+}
+
+define i8 @test5(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.umul.with.overflow.i8(i8 0, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @test5
+; CHECK-NEXT: store i1 false, i1* %overflowPtr
+; CHECK-NEXT: ret i8 0
+}
+
+define i8 @test6(i8 %A, i1* %overflowPtr) {
+ %x = call %overflow.result @llvm.umul.with.overflow.i8(i8 1, i8 %A)
+ %y = extractvalue %overflow.result %x, 0
+ %z = extractvalue %overflow.result %x, 1
+ store i1 %z, i1* %overflowPtr
+ ret i8 %y
+; CHECK: @test6
+; CHECK-NEXT: store i1 false, i1* %overflowPtr
+; CHECK-NEXT: ret i8 %A
+}
diff --git a/test/Transforms/InstCombine/or.ll b/test/Transforms/InstCombine/or.ll
index b72480b4f9d0..4a140815f620 100644
--- a/test/Transforms/InstCombine/or.ll
+++ b/test/Transforms/InstCombine/or.ll
@@ -1,7 +1,8 @@
; This test makes sure that these instructions are properly eliminated.
-;
; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+
define i32 @test1(i32 %A) {
%B = or i32 %A, 0
ret i32 %B
@@ -253,3 +254,44 @@ define i1 @test25(i32 %A, i32 %B) {
; CHECK-NEXT: %F = and i1
; CHECK-NEXT: ret i1 %F
}
+
+; PR5634
+define i1 @test26(i32 %A, i32 %B) {
+ %C1 = icmp eq i32 %A, 0
+ %C2 = icmp eq i32 %B, 0
+ ; (A == 0) & (A == 0) --> (A|B) == 0
+ %D = and i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test26
+; CHECK: or i32 %A, %B
+; CHECK: icmp eq i32 {{.*}}, 0
+; CHECK: ret i1
+}
+
+; PR5634
+define i1 @test27(i32* %A, i32* %B) {
+ %C1 = icmp eq i32* %A, null
+ %C2 = icmp eq i32* %B, null
+ ; (A == 0) & (A == 0) --> (A|B) == 0
+ %D = and i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test27
+; CHECK: ptrtoint i32* %A
+; CHECK: ptrtoint i32* %B
+; CHECK: or i32
+; CHECK: icmp eq i32 {{.*}}, 0
+; CHECK: ret i1
+}
+
+; PR5634
+define i1 @test28(i32 %A, i32 %B) {
+ %C1 = icmp ne i32 %A, 0
+ %C2 = icmp ne i32 %B, 0
+ ; (A != 0) | (A != 0) --> (A|B) != 0
+ %D = or i1 %C1, %C2
+ ret i1 %D
+; CHECK: @test28
+; CHECK: or i32 %A, %B
+; CHECK: icmp ne i32 {{.*}}, 0
+; CHECK: ret i1
+}
diff --git a/test/Transforms/InstCombine/or2.ll b/test/Transforms/InstCombine/or2.ll
deleted file mode 100644
index c01229a78a0d..000000000000
--- a/test/Transforms/InstCombine/or2.ll
+++ /dev/null
@@ -1,12 +0,0 @@
-; This test makes sure that these instructions are properly eliminated.
-;
-; RUN: opt < %s -instcombine -S | grep -v xor | not grep {or }
-
-; PR1738
-define i1 @test1(double %X, double %Y) {
- %tmp9 = fcmp uno double %X, 0.000000e+00 ; <i1> [#uses=1]
- %tmp13 = fcmp uno double %Y, 0.000000e+00 ; <i1> [#uses=1]
- %bothcond = or i1 %tmp13, %tmp9 ; <i1> [#uses=1]
- ret i1 %bothcond
-}
-
diff --git a/test/Transforms/InstCombine/phi-merge.ll b/test/Transforms/InstCombine/phi-merge.ll
deleted file mode 100644
index c41f50325d6f..000000000000
--- a/test/Transforms/InstCombine/phi-merge.ll
+++ /dev/null
@@ -1,31 +0,0 @@
-; RUN: opt < %s -instcombine -S | not grep {phi i32}
-; PR1777
-
-declare i1 @rrr()
-
-define i1 @zxcv() {
-entry:
-%a = alloca i32
-%i = ptrtoint i32* %a to i32
-%b = call i1 @rrr()
-br i1 %b, label %one, label %two
-
-one:
-%x = phi i32 [%i, %entry], [%y, %two]
-%c = call i1 @rrr()
-br i1 %c, label %two, label %end
-
-two:
-%y = phi i32 [%i, %entry], [%x, %one]
-%d = call i1 @rrr()
-br i1 %d, label %one, label %end
-
-end:
-%f = phi i32 [ %x, %one], [%y, %two]
-; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
-; even though %f must equal %i at this point
-%g = inttoptr i32 %f to i32*
-store i32 10, i32* %g
-%z = call i1 @rrr()
-ret i1 %z
-}
diff --git a/test/Transforms/InstCombine/shufflevec-constant.ll b/test/Transforms/InstCombine/shufflevec-constant.ll
index 2c667903b1eb..29ae5a79824a 100644
--- a/test/Transforms/InstCombine/shufflevec-constant.ll
+++ b/test/Transforms/InstCombine/shufflevec-constant.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -instcombine -S | grep "2 x float"
+; RUN: opt < %s -instcombine -S | grep {ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0x7FF0000000000000, float 0x7FF0000000000000>}
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "i386-apple-darwin9"
diff --git a/test/Transforms/InstCombine/store-merge.ll b/test/Transforms/InstCombine/store-merge.ll
deleted file mode 100644
index 06d497d10dbf..000000000000
--- a/test/Transforms/InstCombine/store-merge.ll
+++ /dev/null
@@ -1,37 +0,0 @@
-; RUN: opt < %s -instcombine -S | \
-; RUN: grep {ret i32 %.toremerge} | count 2
-;; Simple sinking tests
-
-; "if then else"
-define i32 @test1(i1 %C) {
- %A = alloca i32
- br i1 %C, label %Cond, label %Cond2
-
-Cond:
- store i32 -987654321, i32* %A
- br label %Cont
-
-Cond2:
- store i32 47, i32* %A
- br label %Cont
-
-Cont:
- %V = load i32* %A
- ret i32 %V
-}
-
-; "if then"
-define i32 @test2(i1 %C) {
- %A = alloca i32
- store i32 47, i32* %A
- br i1 %C, label %Cond, label %Cont
-
-Cond:
- store i32 -987654321, i32* %A
- br label %Cont
-
-Cont:
- %V = load i32* %A
- ret i32 %V
-}
-
diff --git a/test/Transforms/InstCombine/store.ll b/test/Transforms/InstCombine/store.ll
index 314441eb8653..64460d7a6d61 100644
--- a/test/Transforms/InstCombine/store.ll
+++ b/test/Transforms/InstCombine/store.ll
@@ -6,6 +6,7 @@ define void @test1(i32* %P) {
store i32 124, i32* null
ret void
; CHECK: @test1(
+; CHECK-NEXT: store i32 123, i32* undef
; CHECK-NEXT: store i32 undef, i32* null
; CHECK-NEXT: ret void
}