diff options
author | Florian Hahn <florian.hahn@arm.com> | 2018-07-02 12:44:04 +0000 |
---|---|---|
committer | Florian Hahn <florian.hahn@arm.com> | 2018-07-02 12:44:04 +0000 |
commit | 4ebba909a209b93c1f0cb626412aa2687c0fb36d (patch) | |
tree | b2ae6d89b96b5b29c300caa49097540cb68677f6 /llvm/test/Transforms/SCCP | |
parent | a2d9c2be3f8051b795efc4d544c231840181d812 (diff) | |
download | bcm5719-llvm-4ebba909a209b93c1f0cb626412aa2687c0fb36d.tar.gz bcm5719-llvm-4ebba909a209b93c1f0cb626412aa2687c0fb36d.zip |
Recommit r328307: [IPSCCP] Use constant range information for comparisons of parameters.
This version contains a fix to add values for which the state in ParamState change
to the worklist if the state in ValueState did not change. To avoid adding the
same value multiple times, mergeInValue returns true, if it added the value to
the worklist. The value is added to the worklist depending on its state in
ValueState.
Original message:
For comparisons with parameters, we can use the ParamState lattice
elements which also provide constant range information. This improves
the code for PR33253 further and gets us closer to use
ValueLatticeElement for all values.
Also, as we are using the range information in the solver directly, we
do not need tryToReplaceWithConstantRange afterwards anymore.
Reviewers: dberlin, mssimpso, davide, efriedma
Reviewed By: mssimpso
Differential Revision: https://reviews.llvm.org/D43762
llvm-svn: 336098
Diffstat (limited to 'llvm/test/Transforms/SCCP')
-rw-r--r-- | llvm/test/Transforms/SCCP/ip-constant-ranges.ll | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/llvm/test/Transforms/SCCP/ip-constant-ranges.ll b/llvm/test/Transforms/SCCP/ip-constant-ranges.ll index 22a239d1208..704ea97179b 100644 --- a/llvm/test/Transforms/SCCP/ip-constant-ranges.ll +++ b/llvm/test/Transforms/SCCP/ip-constant-ranges.ll @@ -2,11 +2,7 @@ ; Constant range for %a is [1, 48) and for %b is [301, 1000) ; CHECK-LABEL: f1 -; CHECK-NOT: icmp -; CHECK: %a.1 = select i1 false, i32 1, i32 2 -; CHECK: %b.1 = select i1 true, i32 1, i32 2 -; CHECK: %a.2 = select i1 false, i32 1, i32 2 -; CHECK: %b.2 = select i1 true, i32 1, i32 2 +; CHECK: ret i32 undef define internal i32 @f1(i32 %a, i32 %b) { entry: %cmp.a = icmp sgt i32 %a, 300 @@ -28,10 +24,11 @@ entry: ; CHECK-LABEL: f2 ; CHECK: %cmp = icmp sgt i32 %x, 300 ; CHECK: %res1 = select i1 %cmp, i32 1, i32 2 -; CHECK-NEXT: %res2 = select i1 true, i32 3, i32 4 -; CHECK-NEXT: %res3 = select i1 true, i32 5, i32 6 ; CHECK-NEXT: %res4 = select i1 %cmp4, i32 3, i32 4 -; CHECK-NEXT: %res5 = select i1 true, i32 5, i32 6 +; CHECK-NEXT: %res6 = add i32 %res1, 3 +; CHECK-NEXT: %res7 = add i32 5, %res4 +; CHECK-NEXT: %res = add i32 %res6, 5 +; CHECK-NEXT: ret i32 %res define internal i32 @f2(i32 %x) { entry: %cmp = icmp sgt i32 %x, 300 @@ -57,8 +54,7 @@ entry: %call2 = tail call i32 @f1(i32 47, i32 999) %call3 = tail call i32 @f2(i32 47) %call4 = tail call i32 @f2(i32 301) - %res = add nsw i32 %call1, %call2 - %res.1 = add nsw i32 %res, %call3 + %res.1 = add nsw i32 12, %call3 %res.2 = add nsw i32 %res.1, %call4 ret i32 %res.2 } @@ -145,9 +141,9 @@ define double @test_struct({ double, double } %test) { ; Constant range for %x is [47, 302) ; CHECK-LABEL: @f5 ; CHECK-NEXT: entry: -; CHECK-NEXT: %res1 = select i1 undef, i32 1, i32 2 -; CHECK-NEXT: %res2 = select i1 undef, i32 3, i32 4 -; CHECK-NEXT: %res = add i32 %res1, %res2 +; CHECK-NEXT: %cmp = icmp sgt i32 %x, undef +; CHECK-NEXT: %res1 = select i1 %cmp, i32 1, i32 2 +; CHECK-NEXT: %res = add i32 %res1, 3 ; CHECK-NEXT: ret i32 %res define internal i32 @f5(i32 %x) { entry: @@ -167,3 +163,36 @@ entry: %res = add nsw i32 %call1, %call2 ret i32 %res } + +; Make sure we do re-evaluate the function after ParamState changes. +; CHECK-LABEL: @recursive_f +; CHECK-LABEL: entry: +; CHECK: %cmp = icmp eq i32 %i, 0 +; CHECK-NEXT: br i1 %cmp, label %if.then, label %if.else +define internal i32 @recursive_f(i32 %i) { +entry: + %cmp = icmp eq i32 %i, 0 + br i1 %cmp, label %if.then, label %if.else + +if.then: ; preds = %entry + br label %return + +if.else: ; preds = %entry + %sub = sub nsw i32 %i, 1 + %call = call i32 @recursive_f(i32 %sub) + %add = add i32 %i, %call + br label %return + +return: ; preds = %if.else, %if.then + %retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.else ] + ret i32 %retval.0 +} + +; CHECK-LABEL: @caller5 +; CHECK: %call = call i32 @recursive_f(i32 42) +; CHECK-NEXT: ret i32 %call +define i32 @caller5() { +entry: + %call = call i32 @recursive_f(i32 42) + ret i32 %call +} |