summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorIgor Laevsky <igmyrj@gmail.com>2017-12-05 12:18:15 +0000
committerIgor Laevsky <igmyrj@gmail.com>2017-12-05 12:18:15 +0000
commitb8aa60d240c62f4a2e7eaaba707dceaaff7704e8 (patch)
treec4faeadb2c4046c99c54c1063bcf52aeb611c45a /test
parentf071b970e463948c160677d37e8c17b7776663cc (diff)
[InstCombine] Don't crash on out of bounds shifts
Differential Revision: https://reviews.llvm.org/D40649 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319761 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Transforms/InstCombine/out-of-bounds-indexes.ll33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/out-of-bounds-indexes.ll b/test/Transforms/InstCombine/out-of-bounds-indexes.ll
new file mode 100644
index 00000000000..a1887d27550
--- /dev/null
+++ b/test/Transforms/InstCombine/out-of-bounds-indexes.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; Check that we don't crash on unreasonable constant indexes
+
+define i32 @test_out_of_bounds(i32 %a, i1 %x, i1 %y) {
+; CHECK-LABEL: @test_out_of_bounds(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A:%.*]], 3
+; CHECK-NEXT: tail call void @llvm.assume(i1 false)
+; CHECK-NEXT: ret i32 [[AND1]]
+;
+entry:
+ %and1 = and i32 %a, 3
+ %B = lshr i32 %and1, -2147483648
+ %cmp = icmp eq i32 %B, 1
+ tail call void @llvm.assume(i1 %cmp)
+ ret i32 %and1
+}
+
+define i128 @test_non64bit(i128 %a) {
+; CHECK-LABEL: @test_non64bit(
+; CHECK-NEXT: [[AND1:%.*]] = and i128 [[A:%.*]], 3
+; CHECK-NEXT: tail call void @llvm.assume(i1 false)
+; CHECK-NEXT: ret i128 [[AND1]]
+;
+ %and1 = and i128 %a, 3
+ %B = lshr i128 %and1, -1
+ %cmp = icmp eq i128 %B, 1
+ tail call void @llvm.assume(i1 %cmp)
+ ret i128 %and1
+}
+
+declare void @llvm.assume(i1)