aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-10-22 19:58:20 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-10-22 19:58:20 +0000
commit614fef6d5a1e24d01ffe7247b1841fd7e08e1e85 (patch)
treefde79a92e8e5d07bd5b179e32d877d8557ebf9f6 /test
parent5eebf6ff2052c2ee928abaf387b6458a765393c4 (diff)
downloadexternal_llvm-614fef6d5a1e24d01ffe7247b1841fd7e08e1e85.zip
external_llvm-614fef6d5a1e24d01ffe7247b1841fd7e08e1e85.tar.gz
external_llvm-614fef6d5a1e24d01ffe7247b1841fd7e08e1e85.tar.bz2
Make SCEV's brute force analysis stronger in two ways. Firstly, we should be
able to constant fold load instructions where the argument is a constant. Second, we should be able to watch multiple PHI nodes through the loop; this patch only supports PHIs in loop headers, more can be done here. With this patch, we now constant evaluate: static const int arr[] = {1, 2, 3, 4, 5}; int test() { int sum = 0; for (int i = 0; i < 5; ++i) sum += arr[i]; return sum; } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Analysis/ScalarEvolution/load.ll33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/Analysis/ScalarEvolution/load.ll b/test/Analysis/ScalarEvolution/load.ll
new file mode 100644
index 0000000..2035152
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/load.ll
@@ -0,0 +1,33 @@
+; RUN: opt -analyze -scalar-evolution < %s 2>&1 | FileCheck %s
+; PR11034
+
+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:32:32-n8:16:32"
+target triple = "i386-pc-linux-gnu"
+
+@arr1 = internal unnamed_addr constant [50 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50], align 4
+@arr2 = internal unnamed_addr constant [50 x i32] [i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0], align 4
+
+define i32 @test1() nounwind readnone {
+; CHECK: test1
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %sum.04 = phi i32 [ 0, %entry ], [ %add2, %for.body ]
+; CHECK: --> %sum.04{{ *}}Exits: 2450
+ %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %arrayidx = getelementptr inbounds [50 x i32]* @arr1, i32 0, i32 %i.03
+ %0 = load i32* %arrayidx, align 4
+; CHECK: --> %0{{ *}}Exits: 50
+ %arrayidx1 = getelementptr inbounds [50 x i32]* @arr2, i32 0, i32 %i.03
+ %1 = load i32* %arrayidx1, align 4
+; CHECK: --> %1{{ *}}Exits: 0
+ %add = add i32 %0, %sum.04
+ %add2 = add i32 %add, %1
+ %inc = add nsw i32 %i.03, 1
+ %cmp = icmp eq i32 %inc, 50
+ br i1 %cmp, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret i32 %add2
+}