diff options
| author | Philip Reames <listmail@philipreames.com> | 2016-02-12 00:09:18 +0000 |
|---|---|---|
| committer | Philip Reames <listmail@philipreames.com> | 2016-02-12 00:09:18 +0000 |
| commit | 854a84c0b0a3386943bdc6bf67d8f2e36c4496db (patch) | |
| tree | 46c06bf1897b87d63b2f63e863407c632f840ab3 /llvm/test | |
| parent | 9ddad935b93906f8b0389b9120ce29ff0206585f (diff) | |
| download | bcm5719-llvm-854a84c0b0a3386943bdc6bf67d8f2e36c4496db.tar.gz bcm5719-llvm-854a84c0b0a3386943bdc6bf67d8f2e36c4496db.zip | |
[LVI] Improve select handling to use condition
This patches teaches LVI to recognize clamp idioms (e.g. select(a > 5, a, 5) will always produce something greater than 5.
The tests end up being somewhat simplistic because trying to exercise the case I actually care about (a loop with a range check on a clamped secondary induction variable) ends up tripping across a couple of other imprecisions in the analysis. Ah, the joys of LVI...
Differential Revision: http://reviews.llvm.org/D16827
llvm-svn: 260627
Diffstat (limited to 'llvm/test')
| -rw-r--r-- | llvm/test/Transforms/CorrelatedValuePropagation/select.ll | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/select.ll b/llvm/test/Transforms/CorrelatedValuePropagation/select.ll index cab88766113..d237521f301 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/select.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/select.ll @@ -167,3 +167,52 @@ exit: ; CHECK: ret i1 true ret i1 true } + +;; Using the condition to clamp the result +;; + +define i1 @test5(i32* %p, i1 %unknown) { +; CHECK-LABEL: @test5 + %pval = load i32, i32* %p + %cmp1 = icmp slt i32 %pval, 255 + br i1 %cmp1, label %next, label %exit + +next: + %cond = icmp sgt i32 %pval, 0 + %min = select i1 %cond, i32 %pval, i32 5 + ;; TODO: This pointless branch shouldn't be neccessary + br label %next2 +next2: +; CHECK-LABEL: next2: +; CHECK: ret i1 false + %res = icmp eq i32 %min, -1 + ret i1 %res + +exit: +; CHECK-LABEL: exit: +; CHECK: ret i1 true + ret i1 true +} + +define i1 @test6(i32* %p, i1 %unknown) { +; CHECK-LABEL: @test6 + %pval = load i32, i32* %p + %cmp1 = icmp ult i32 %pval, 255 + br i1 %cmp1, label %next, label %exit + +next: + %cond = icmp ne i32 %pval, 254 + %sel = select i1 %cond, i32 %pval, i32 1 + ;; TODO: This pointless branch shouldn't be neccessary + br label %next2 +next2: +; CHECK-LABEL: next2: +; CHECK: ret i1 true + %res = icmp slt i32 %sel, 254 + ret i1 %res + +exit: +; CHECK-LABEL: exit: +; CHECK: ret i1 true + ret i1 true +} |

