summaryrefslogtreecommitdiff
path: root/test/Transforms/InstSimplify
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-10-27 19:16:21 +0000
committerDuncan Sands <baldrick@free.fr>2011-10-27 19:16:21 +0000
commit32a43cc0fc3cd42702d7859eaa58dd42f561a54d (patch)
tree56449a56539910bed314212d85f556a4d59768c0 /test/Transforms/InstSimplify
parent6eb1ed8c9c6a6d3f9b57900c44fc076d08a358bd (diff)
downloadllvm-32a43cc0fc3cd42702d7859eaa58dd42f561a54d.tar.gz
llvm-32a43cc0fc3cd42702d7859eaa58dd42f561a54d.tar.bz2
llvm-32a43cc0fc3cd42702d7859eaa58dd42f561a54d.tar.xz
Reapply commit 143028 with a fix: the problem was casting a ConstantExpr Mul
using BinaryOperator (which only works for instructions) when it should have been a cast to OverflowingBinaryOperator (which also works for constants). While there, correct a few other dubious looking uses of BinaryOperator. Thanks to Chad Rosier for the testcase. Original commit message: My super-optimizer noticed that we weren't folding this expression to true: (x *nsw x) sgt 0, where x = (y | 1). This occurs in 464.h264ref. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143125 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/InstSimplify')
-rw-r--r--test/Transforms/InstSimplify/2011-10-27-BinOpCrash.ll12
-rw-r--r--test/Transforms/InstSimplify/compare.ll31
2 files changed, 43 insertions, 0 deletions
diff --git a/test/Transforms/InstSimplify/2011-10-27-BinOpCrash.ll b/test/Transforms/InstSimplify/2011-10-27-BinOpCrash.ll
new file mode 100644
index 0000000000..a10081a42d
--- /dev/null
+++ b/test/Transforms/InstSimplify/2011-10-27-BinOpCrash.ll
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine
+
+@_ZN11xercesc_2_5L11gDigitCharsE = external constant [32 x i16], align 2
+@_ZN11xercesc_2_5L10gBaseCharsE = external constant [354 x i16], align 2
+@_ZN11xercesc_2_5L17gIdeographicCharsE = external constant [7 x i16], align 2
+@_ZN11xercesc_2_5L15gCombiningCharsE = external constant [163 x i16], align 2
+
+define i32 @_ZN11xercesc_2_515XMLRangeFactory11buildRangesEv(i32 %x) {
+ %a = add i32 %x, add (i32 add (i32 ashr (i32 add (i32 mul (i32 ptrtoint ([32 x i16]* @_ZN11xercesc_2_5L11gDigitCharsE to i32), i32 -1), i32 ptrtoint (i16* getelementptr inbounds ([32 x i16]* @_ZN11xercesc_2_5L11gDigitCharsE, i32 0, i32 30) to i32)), i32 1), i32 ashr (i32 add (i32 mul (i32 ptrtoint ([7 x i16]* @_ZN11xercesc_2_5L17gIdeographicCharsE to i32), i32 -1), i32 ptrtoint (i16* getelementptr inbounds ([7 x i16]* @_ZN11xercesc_2_5L17gIdeographicCharsE, i32 0, i32 4) to i32)), i32 1)), i32 8)
+ %b = add i32 %a, %x
+ ret i32 %b
+}
diff --git a/test/Transforms/InstSimplify/compare.ll b/test/Transforms/InstSimplify/compare.ll
index 2cbd641a74..3ece118902 100644
--- a/test/Transforms/InstSimplify/compare.ll
+++ b/test/Transforms/InstSimplify/compare.ll
@@ -323,3 +323,34 @@ define i1 @and1(i32 %X) {
ret i1 %B
; CHECK: ret i1 false
}
+
+define i1 @mul1(i32 %X) {
+; CHECK: @mul1
+; Square of a non-zero number is non-zero if there is no overflow.
+ %Y = or i32 %X, 1
+ %M = mul nuw i32 %Y, %Y
+ %C = icmp eq i32 %M, 0
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @mul2(i32 %X) {
+; CHECK: @mul2
+; Square of a non-zero number is positive if there is no signed overflow.
+ %Y = or i32 %X, 1
+ %M = mul nsw i32 %Y, %Y
+ %C = icmp sgt i32 %M, 0
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
+define i1 @mul3(i32 %X, i32 %Y) {
+; CHECK: @mul3
+; Product of non-negative numbers is non-negative if there is no signed overflow.
+ %XX = mul nsw i32 %X, %X
+ %YY = mul nsw i32 %Y, %Y
+ %M = mul nsw i32 %XX, %YY
+ %C = icmp sge i32 %M, 0
+ ret i1 %C
+; CHECK: ret i1 true
+}