summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/StraightLineStrengthReduce
diff options
context:
space:
mode:
authorJingyue Wu <jingyue@google.com>2016-07-09 19:13:18 +0000
committerJingyue Wu <jingyue@google.com>2016-07-09 19:13:18 +0000
commitdebce55ac3048eda31c2e97ab9eefc0d10c45fd2 (patch)
tree2a69b2b84b0a3276a6c16d82e11bfba498a8081a /llvm/test/Transforms/StraightLineStrengthReduce
parent6170b4bebdcf3c9eae3eb0d88dbe855c98977a08 (diff)
downloadbcm5719-llvm-debce55ac3048eda31c2e97ab9eefc0d10c45fd2.tar.gz
bcm5719-llvm-debce55ac3048eda31c2e97ab9eefc0d10c45fd2.zip
[SLSR] Fix crash on handling 128-bit integers.
ConstantInt::getSExtValue may fail on >64-bit integers. Add checks to call getSExtValue only on narrow integers. As a minor aside, simplify slsr-gep.ll to remove unnecessary load instructions. llvm-svn: 274982
Diffstat (limited to 'llvm/test/Transforms/StraightLineStrengthReduce')
-rw-r--r--llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll15
-rw-r--r--llvm/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll70
2 files changed, 53 insertions, 32 deletions
diff --git a/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll b/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll
index e25ddc2888a..b4f448ace2a 100644
--- a/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll
+++ b/llvm/test/Transforms/StraightLineStrengthReduce/slsr-add.ll
@@ -98,4 +98,19 @@ define void @simple_enough(i32 %b, i32 %s) {
ret void
}
+define void @slsr_strided_add_128bit(i128 %b, i128 %s) {
+; CHECK-LABEL: @slsr_strided_add_128bit(
+ %s125 = shl i128 %s, 125
+ %s126 = shl i128 %s, 126
+ %1 = add i128 %b, %s125
+; CHECK: [[t1:%[a-zA-Z0-9]+]] = add i128 %b, %s125
+ call void @bar(i128 %1)
+ %2 = add i128 %b, %s126
+; CHECK: [[t2:%[a-zA-Z0-9]+]] = add i128 [[t1]], %s125
+ call void @bar(i128 %2)
+; CHECK: call void @bar(i128 [[t2]])
+ ret void
+}
+
declare void @foo(i32)
+declare void @bar(i128)
diff --git a/llvm/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll b/llvm/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll
index bd92780a036..573c33cb858 100644
--- a/llvm/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll
+++ b/llvm/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll
@@ -16,21 +16,18 @@ define void @slsr_gep(i32* %input, i64 %s) {
; CHECK-LABEL: @slsr_gep(
; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0
- %v0 = load i32, i32* %p0
- call void @foo(i32 %v0)
+ call void @foo(i32* %p0)
; v1 = input[s];
%p1 = getelementptr inbounds i32, i32* %input, i64 %s
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %s
- %v1 = load i32, i32* %p1
- call void @foo(i32 %v1)
+ call void @foo(i32* %p1)
; v2 = input[s * 2];
%s2 = shl nsw i64 %s, 1
%p2 = getelementptr inbounds i32, i32* %input, i64 %s2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s
- %v2 = load i32, i32* %p2
- call void @foo(i32 %v2)
+ call void @foo(i32* %p2)
ret void
}
@@ -49,23 +46,20 @@ define void @slsr_gep_sext(i32* %input, i32 %s) {
; CHECK-LABEL: @slsr_gep_sext(
; v0 = input[0];
%p0 = getelementptr inbounds i32, i32* %input, i64 0
- %v0 = load i32, i32* %p0
- call void @foo(i32 %v0)
+ call void @foo(i32* %p0)
; v1 = input[s];
%t = sext i32 %s to i64
%p1 = getelementptr inbounds i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i64 %t
- %v1 = load i32, i32* %p1
- call void @foo(i32 %v1)
+ call void @foo(i32* %p1)
; v2 = input[s * 2];
%s2 = shl nsw i32 %s, 1
%t2 = sext i32 %s2 to i64
%p2 = getelementptr inbounds i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t
- %v2 = load i32, i32* %p2
- call void @foo(i32 %v2)
+ call void @foo(i32* %p2)
ret void
}
@@ -85,23 +79,20 @@ define void @slsr_gep_2d([10 x [5 x i32]]* %input, i64 %s, i64 %t) {
; CHECK-LABEL: @slsr_gep_2d(
; v0 = input[s][t];
%p0 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s, i64 %t
- %v0 = load i32, i32* %p0
- call void @foo(i32 %v0)
+ call void @foo(i32* %p0)
; v1 = input[s * 2][t];
%s2 = shl nsw i64 %s, 1
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = mul i64 %s, 5
%p1 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s2, i64 %t
; CHECK: %p1 = getelementptr inbounds i32, i32* %p0, i64 [[BUMP]]
- %v1 = load i32, i32* %p1
- call void @foo(i32 %v1)
+ call void @foo(i32* %p1)
; v3 = input[s * 3][t];
%s3 = mul nsw i64 %s, 3
%p2 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s3, i64 %t
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 [[BUMP]]
- %v2 = load i32, i32* %p2
- call void @foo(i32 %v2)
+ call void @foo(i32* %p2)
ret void
}
@@ -118,23 +109,20 @@ define void @slsr_gep_uglygep([10 x [5 x %struct.S]]* %input, i64 %s, i64 %t) {
; CHECK-LABEL: @slsr_gep_uglygep(
; v0 = input[s][t].f1;
%p0 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s, i64 %t, i32 0
- %v0 = load i64, i64* %p0
- call void @bar(i64 %v0)
+ call void @bar(i64* %p0)
; v1 = input[s * 2][t].f1;
%s2 = shl nsw i64 %s, 1
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = mul i64 %s, 60
%p1 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s2, i64 %t, i32 0
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
- %v1 = load i64, i64* %p1
- call void @bar(i64 %v1)
+ call void @bar(i64* %p1)
; v2 = input[s * 3][t].f1;
%s3 = mul nsw i64 %s, 3
%p2 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s3, i64 %t, i32 0
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
- %v2 = load i64, i64* %p2
- call void @bar(i64 %v2)
+ call void @bar(i64* %p2)
ret void
}
@@ -143,26 +131,44 @@ define void @slsr_out_of_bounds_gep(i32* %input, i32 %s) {
; CHECK-LABEL: @slsr_out_of_bounds_gep(
; v0 = input[0];
%p0 = getelementptr i32, i32* %input, i64 0
- %v0 = load i32, i32* %p0
- call void @foo(i32 %v0)
+ call void @foo(i32* %p0)
; v1 = input[(long)s];
%t = sext i32 %s to i64
%p1 = getelementptr i32, i32* %input, i64 %t
; CHECK: %p1 = getelementptr i32, i32* %input, i64 %t
- %v1 = load i32, i32* %p1
- call void @foo(i32 %v1)
+ call void @foo(i32* %p1)
; v2 = input[(long)(s * 2)];
%s2 = shl nsw i32 %s, 1
%t2 = sext i32 %s2 to i64
%p2 = getelementptr i32, i32* %input, i64 %t2
; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t
- %v2 = load i32, i32* %p2
- call void @foo(i32 %v2)
+ call void @foo(i32* %p2)
ret void
}
-declare void @foo(i32)
-declare void @bar(i64)
+define void @slsr_gep_128bit(i32* %input, i128 %s) {
+; CHECK-LABEL: @slsr_gep_128bit(
+ ; p0 = &input[0]
+ %p0 = getelementptr inbounds i32, i32* %input, i128 0
+ call void @foo(i32* %p0)
+
+ ; p1 = &input[s << 125]
+ %s125 = shl nsw i128 %s, 125
+ %p1 = getelementptr inbounds i32, i32* %input, i128 %s125
+; CHECK: %p1 = getelementptr inbounds i32, i32* %input, i128 %s125
+ call void @foo(i32* %p1)
+
+ ; p2 = &input[s << 126]
+ %s126 = shl nsw i128 %s, 126
+ %p2 = getelementptr inbounds i32, i32* %input, i128 %s126
+; CHECK: %p2 = getelementptr inbounds i32, i32* %input, i128 %s126
+ call void @foo(i32* %p2)
+
+ ret void
+}
+
+declare void @foo(i32*)
+declare void @bar(i64*)
OpenPOWER on IntegriCloud