summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-11-30 03:42:12 +0000
committerBill Wendling <isanbard@gmail.com>2008-11-30 03:42:12 +0000
commite1196d6d3efabfc58103acc9076ad946d3574a04 (patch)
treecf179d0e8850608a3ca59d46b4729c512df0d6cf /test
parent4a69bade2385022ca776edc22150f3b750cdf23c (diff)
downloadllvm-e1196d6d3efabfc58103acc9076ad946d3574a04.tar.gz
llvm-e1196d6d3efabfc58103acc9076ad946d3574a04.tar.bz2
llvm-e1196d6d3efabfc58103acc9076ad946d3574a04.tar.xz
Instcombine was illegally transforming -X/C into X/-C when either X or C
overflowed on negation. This commit checks to make sure that neithe C nor X overflows. This requires that the RHS of X (a subtract instruction) be a constant integer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60275 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Transforms/InstCombine/apint-sub.ll8
-rw-r--r--test/Transforms/InstCombine/sdiv-1.ll22
-rw-r--r--test/Transforms/InstCombine/sub.ll8
3 files changed, 32 insertions, 6 deletions
diff --git a/test/Transforms/InstCombine/apint-sub.ll b/test/Transforms/InstCombine/apint-sub.ll
index 12f366de7f..2ff763c9f5 100644
--- a/test/Transforms/InstCombine/apint-sub.ll
+++ b/test/Transforms/InstCombine/apint-sub.ll
@@ -3,7 +3,7 @@
;
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
-; RUN: grep -v {sub i19 %Cok, %Bok} | not grep sub
+; RUN: grep -v {sub i19 %Cok, %Bok} | grep -v {sub i25 0, %Aok} | not grep sub
; END.
define i23 @test1(i23 %A) {
@@ -107,8 +107,10 @@ define i51 @test16(i51 %A) {
ret i51 %Y
}
-define i25 @test17(i25 %A) {
- %B = sub i25 0, %A ; <i25> [#uses=1]
+; Can't fold subtract here because negation it might oveflow.
+; PR3142
+define i25 @test17(i25 %Aok) {
+ %B = sub i25 0, %Aok ; <i25> [#uses=1]
%C = sdiv i25 %B, 1234 ; <i25> [#uses=1]
ret i25 %C
}
diff --git a/test/Transforms/InstCombine/sdiv-1.ll b/test/Transforms/InstCombine/sdiv-1.ll
new file mode 100644
index 0000000000..c10bd77515
--- /dev/null
+++ b/test/Transforms/InstCombine/sdiv-1.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-as < %s | opt -instcombine -inline | llvm-dis | grep {715827882} | count 2
+; PR3142
+
+define i32 @a(i32 %X) nounwind readnone {
+entry:
+ %0 = sub i32 0, %X
+ %1 = sdiv i32 %0, -3
+ ret i32 %1
+}
+
+define i32 @b(i32 %X) nounwind readnone {
+entry:
+ %0 = call i32 @a(i32 -2147483648)
+ ret i32 %0
+}
+
+define i32 @c(i32 %X) nounwind readnone {
+entry:
+ %0 = sub i32 0, -2147483648
+ %1 = sdiv i32 %0, -3
+ ret i32 %1
+}
diff --git a/test/Transforms/InstCombine/sub.ll b/test/Transforms/InstCombine/sub.ll
index da6d710f6b..1ab4eaf1b4 100644
--- a/test/Transforms/InstCombine/sub.ll
+++ b/test/Transforms/InstCombine/sub.ll
@@ -1,7 +1,7 @@
; This test makes sure that these instructions are properly eliminated.
;
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
-; RUN: grep -v {sub i32 %Cok, %Bok} | not grep sub
+; RUN: grep -v {sub i32 %Cok, %Bok} | grep -v {sub i32 0, %Aok} | not grep sub
define i32 @test1(i32 %A) {
%B = sub i32 %A, %A ; <i32> [#uses=1]
@@ -104,8 +104,10 @@ define i32 @test16(i32 %A) {
ret i32 %Y
}
-define i32 @test17(i32 %A) {
- %B = sub i32 0, %A ; <i32> [#uses=1]
+; Can't fold subtract here because negation it might oveflow.
+; PR3142
+define i32 @test17(i32 %Aok) {
+ %B = sub i32 0, %Aok ; <i32> [#uses=1]
%C = sdiv i32 %B, 1234 ; <i32> [#uses=1]
ret i32 %C
}