diff options
| author | Jun Bum Lim <junbuml@codeaurora.org> | 2016-02-11 15:50:07 +0000 |
|---|---|---|
| committer | Jun Bum Lim <junbuml@codeaurora.org> | 2016-02-11 15:50:07 +0000 |
| commit | 339e9723c12dfc046b1493bb75891515127ff0ff (patch) | |
| tree | dc9b7432e371db8ea8acbd7066171b8157ee7790 /llvm/test | |
| parent | e3b963d5eea70d510e5ad5d852ce74a2642886e1 (diff) | |
| download | bcm5719-llvm-339e9723c12dfc046b1493bb75891515127ff0ff.tar.gz bcm5719-llvm-339e9723c12dfc046b1493bb75891515127ff0ff.zip | |
[InstCombine] Simplify a known nonzero incoming value of PHI
Summary:
When a PHI is used only to be compared with zero, it is possible to replace an
incoming value with any non-zero constant if the incoming value can be proved as
a known nonzero value. For example, in below code, we can replace the incoming value %v with
any non-zero constant based on the fact that the PHI is only used to be compared with zero
and %v is a known non-zero value:
%v = select %cond, 1, 2
%p = phi [%v, BB] ...
%c = icmp eq, %p, 0
Reviewers: mcrosier, jmolloy, sanjoy
Subscribers: hfinkel, mcrosier, majnemer, llvm-commits, haicheng, bmakam, mssimpso, gberry
Differential Revision: http://reviews.llvm.org/D16240
llvm-svn: 260530
Diffstat (limited to 'llvm/test')
| -rw-r--r-- | llvm/test/Transforms/InstCombine/phi.ll | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/phi.ll b/llvm/test/Transforms/InstCombine/phi.ll index 7e3bdd0e0aa..c417737fdf2 100644 --- a/llvm/test/Transforms/InstCombine/phi.ll +++ b/llvm/test/Transforms/InstCombine/phi.ll @@ -784,3 +784,98 @@ if.end: ; preds = %if.else, %if.then declare void @dummy() +; CHECK-LABEL: @phi_knownnonzero_eq +; CHECK-LABEL: if.then: +; CHECK-NOT: select +; CHECK-LABEL: if.end: +; CHECK: phi i32 [ 1, %if.then ] +define i1 @phi_knownnonzero_eq(i32 %n, i32 %s, i32* nocapture readonly %P) { +entry: + %tobool = icmp slt i32 %n, %s + br i1 %tobool, label %if.end, label %if.then + +if.then: ; preds = %entry + %0 = load i32, i32* %P + %cmp = icmp eq i32 %n, %0 + %1 = select i1 %cmp, i32 1, i32 2 + br label %if.end + +if.end: ; preds = %entry, %if.then + %a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ] + %cmp1 = icmp eq i32 %a.0, 0 + ret i1 %cmp1 +} + +; CHECK-LABEL: @phi_knownnonzero_ne +; CHECK-LABEL: if.then: +; CHECK-NOT: select +; CHECK-LABEL: if.end: +; CHECK: phi i32 [ 1, %if.then ] +define i1 @phi_knownnonzero_ne(i32 %n, i32 %s, i32* nocapture readonly %P) { +entry: + %tobool = icmp slt i32 %n, %s + br i1 %tobool, label %if.end, label %if.then + +if.then: ; preds = %entry + %0 = load i32, i32* %P + %cmp = icmp eq i32 %n, %0 + %1 = select i1 %cmp, i32 1, i32 2 + br label %if.end + +if.end: ; preds = %entry, %if.then + %a.0 = phi i32 [ %1, %if.then ], [ %n, %entry ] + %cmp1 = icmp ne i32 %a.0, 0 + ret i1 %cmp1 +} + +; CHECK-LABEL: @phi_knownnonzero_eq_2 +; CHECK-LABEL: if.then: +; CHECK-NOT: select +; CHECK-LABEL: if.end: +; CHECK: phi i32 [ 2, %if.else ] +define i1 @phi_knownnonzero_eq_2(i32 %n, i32 %s, i32* nocapture readonly %P) { +entry: + %tobool = icmp slt i32 %n, %s + br i1 %tobool, label %if.then, label %if.end + +if.then: + %tobool2 = icmp slt i32 %n, %s + br i1 %tobool2, label %if.else, label %if.end + +if.else: ; preds = %entry + %0 = load i32, i32* %P + %cmp = icmp eq i32 %n, %0 + %1 = select i1 %cmp, i32 1, i32 2 + br label %if.end + +if.end: ; preds = %entry, %if.then + %a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then] + %cmp1 = icmp eq i32 %a.0, 0 + ret i1 %cmp1 +} + +; CHECK-LABEL: @phi_knownnonzero_ne_2 +; CHECK-LABEL: if.then: +; CHECK-NOT: select +; CHECK-LABEL: if.end: +; CHECK: phi i32 [ 2, %if.else ] +define i1 @phi_knownnonzero_ne_2(i32 %n, i32 %s, i32* nocapture readonly %P) { +entry: + %tobool = icmp slt i32 %n, %s + br i1 %tobool, label %if.then, label %if.end + +if.then: + %tobool2 = icmp slt i32 %n, %s + br i1 %tobool2, label %if.else, label %if.end + +if.else: ; preds = %entry + %0 = load i32, i32* %P + %cmp = icmp eq i32 %n, %0 + %1 = select i1 %cmp, i32 1, i32 2 + br label %if.end + +if.end: ; preds = %entry, %if.then + %a.0 = phi i32 [ %1, %if.else], [ %n, %entry ], [2, %if.then] + %cmp1 = icmp ne i32 %a.0, 0 + ret i1 %cmp1 +} |

