1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/test/Analysis/ScalarEvolution/smax-br-phi-idioms.ll
Sanjoy Das 79fa7ea8a7 [SCEV] Recognize simple br-phi patterns
Summary:
Teach SCEV to match patterns like

```
  br %cond, label %left, label %right
 left:
  br label %merge
 right:
  br label %merge
 merge:
  V = phi [ %x, %left ], [ %y, %right ]
```

as "select %cond, %x, %y".  Before this SCEV would match PHI nodes
exclusively to add recurrences.

This addresses PR25005.

Reviewers: joker.eph, joker-eph, atrick

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D13378

llvm-svn: 249211
2015-10-02 23:09:44 +00:00

105 lines
2.4 KiB
LLVM

; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
define i32 @f0(i32 %x, i32 %y) {
; CHECK-LABEL: Classifying expressions for: @f0
entry:
%c = icmp sgt i32 %y, 0
br i1 %c, label %add, label %merge
add:
%sum = add i32 %x, %y
br label %merge
merge:
%v = phi i32 [ %sum, %add ], [ %x, %entry ]
; CHECK: %v = phi i32 [ %sum, %add ], [ %x, %entry ]
; CHECK-NEXT: --> ((0 smax %y) + %x) U: full-set S: full-set
ret i32 %v
}
define i32 @f1(i32 %x, i32 %y) {
; CHECK-LABEL: Classifying expressions for: @f1
entry:
%c = icmp sge i32 %y, 0
br i1 %c, label %add, label %merge
add:
%sum = add i32 %x, %y
br label %merge
merge:
%v = phi i32 [ %sum, %add ], [ %x, %entry ]
; CHECK: %v = phi i32 [ %sum, %add ], [ %x, %entry ]
; CHECK-NEXT: --> ((0 smax %y) + %x) U: full-set S: full-set
ret i32 %v
}
define i32 @f2(i32 %x, i32 %y, i32* %ptr) {
; CHECK-LABEL: Classifying expressions for: @f2
entry:
%c = icmp sge i32 %y, 0
br i1 %c, label %add, label %merge
add:
%lv = load i32, i32* %ptr
br label %merge
merge:
%v = phi i32 [ %lv, %add ], [ %x, %entry ]
; CHECK: %v = phi i32 [ %lv, %add ], [ %x, %entry ]
; CHECK-NEXT: --> %v U: full-set S: full-set
ret i32 %v
}
define i32 @f3(i32 %x, i32 %init, i32 %lim) {
; CHECK-LABEL: Classifying expressions for: @f3
entry:
br label %loop
loop:
%iv = phi i32 [ %init, %entry ], [ %iv.inc, %merge ]
%iv.inc = add i32 %iv, 1
%c = icmp sge i32 %iv, 0
br i1 %c, label %add, label %merge
add:
%sum = add i32 %x, %iv
br label %merge
merge:
%v = phi i32 [ %sum, %add ], [ %x, %loop ]
; CHECK: %v = phi i32 [ %sum, %add ], [ %x, %loop ]
; CHECK-NEXT: --> ((0 smax {%init,+,1}<%loop>) + %x) U: full-set S: full-set
%be.cond = icmp eq i32 %iv.inc, %lim
br i1 %be.cond, label %loop, label %leave
leave:
ret i32 0
}
define i32 @f4(i32 %x, i32 %init, i32 %lim) {
; CHECK-LABEL: Classifying expressions for: @f4
entry:
%c = icmp sge i32 %init, 0
br i1 %c, label %add, label %merge
add:
br label %loop
loop:
%iv = phi i32 [ %init, %add ], [ %iv.inc, %loop ]
%iv.inc = add i32 %iv, 1
%be.cond = icmp eq i32 %iv.inc, %lim
br i1 %be.cond, label %loop, label %add.cont
add.cont:
%sum = add i32 %x, %iv
br label %merge
merge:
%v = phi i32 [ %sum, %add.cont ], [ %x, %entry ]
; CHECK: %v = phi i32 [ %sum, %add.cont ], [ %x, %entry ]
; CHECK-NEXT: --> %v U: full-set S: full-set
ret i32 %v
}