llvm.org GIT mirror llvm / e79f96c
This patch builds on top of D13378 to handle constant condition. With this patch, clang -O3 optimizes correctly providing > 1000x speedup on this artificial benchmark): for (a=0; a<n; a++) for (b=0; b<n; b++) for (c=0; c<n; c++) for (d=0; d<n; d++) for (e=0; e<n; e++) for (f=0; f<n; f++) x++; From test-suite/SingleSource/Benchmarks/Shootout/nestedloop.c Reviewers: sanjoyd Differential Revision: http://reviews.llvm.org/D13390 From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249431 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
2 changed file(s) with 56 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
39033903 Value *Cond,
39043904 Value *TrueVal,
39053905 Value *FalseVal) {
3906 // Handle "constant" branch or select. This can occur for instance when a
3907 // loop pass transforms an inner loop and moves on to process the outer loop.
3908 if (auto *CI = dyn_cast(Cond))
3909 return getSCEV(CI->isOne() ? TrueVal : FalseVal);
3910
39063911 // Try to match some simple smax or umax patterns.
39073912 auto *ICI = dyn_cast(Cond);
39083913 if (!ICI)
0 ; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
1
2 define i32 @branch_true(i32 %x, i32 %y) {
3 ; CHECK-LABEL: Classifying expressions for: @branch_true
4 entry:
5 br i1 true, label %add, label %merge
6
7 add:
8 %sum = add i32 %x, %y
9 br label %merge
10
11 merge:
12 %v = phi i32 [ %sum, %add ], [ %x, %entry ]
13 ; CHECK: %v = phi i32 [ %sum, %add ], [ %x, %entry ]
14 ; CHECK-NEXT: --> (%x + %y) U: full-set S: full-set
15 ret i32 %v
16 }
17
18 define i32 @branch_false(i32 %x, i32 %y) {
19 ; CHECK-LABEL: Classifying expressions for: @branch_false
20 entry:
21 br i1 false, label %add, label %merge
22
23 add:
24 %sum = add i32 %x, %y
25 br label %merge
26
27 merge:
28 %v = phi i32 [ %sum, %add ], [ %x, %entry ]
29 ; CHECK: %v = phi i32 [ %sum, %add ], [ %x, %entry ]
30 ; CHECK-NEXT: --> %x U: full-set S: full-set
31 ret i32 %v
32 }
33
34 define i32 @select_true(i32 %x, i32 %y) {
35 ; CHECK-LABEL: Classifying expressions for: @select_true
36 entry:
37 %v = select i1 true, i32 %x, i32 %y
38 ; CHECK: %v = select i1 true, i32 %x, i32 %y
39 ; CHECK-NEXT: --> %x U: full-set S: full-set
40 ret i32 %v
41 }
42
43 define i32 @select_false(i32 %x, i32 %y) {
44 ; CHECK-LABEL: Classifying expressions for: @select_false
45 entry:
46 %v = select i1 false, i32 %x, i32 %y
47 ; CHECK: %v = select i1 false, i32 %x, i32 %y
48 ; CHECK-NEXT: --> %y U: full-set S: full-set
49 ret i32 %v
50 }