diff options
| author | Florian Hahn <florian.hahn@arm.com> | 2017-10-10 09:32:38 +0000 |
|---|---|---|
| committer | Florian Hahn <florian.hahn@arm.com> | 2017-10-10 09:32:38 +0000 |
| commit | 22a44bca401a16c070e0d6c11634d5933ba5e66c (patch) | |
| tree | 7f2d61f323c55738dd84089dcca6344a407dbca9 /llvm/test/Transforms/SCCP/ip-constan-ranges.ll | |
| parent | e6dbb58f95c8421a04c77a30c9ce9e43a3be9798 (diff) | |
| download | bcm5719-llvm-22a44bca401a16c070e0d6c11634d5933ba5e66c.tar.gz bcm5719-llvm-22a44bca401a16c070e0d6c11634d5933ba5e66c.zip | |
[SCCP] Propagate integer range info for parameters in IPSCCP.
Summary:
This updates the SCCP solver to use of the ValueElement lattice for
parameters, which provides integer range information. The range
information is used to remove unneeded icmp instructions.
For the following function, f() can be optimized to `ret i32 2` with
this change
source_filename = "sccp.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: norecurse nounwind readnone uwtable
define i32 @main() local_unnamed_addr #0 {
entry:
%call = tail call fastcc i32 @f(i32 1)
%call1 = tail call fastcc i32 @f(i32 47)
%add3 = add nsw i32 %call, %call1
ret i32 %add3
}
; Function Attrs: noinline norecurse nounwind readnone uwtable
define internal fastcc i32 @f(i32 %x) unnamed_addr #1 {
entry:
%c1 = icmp sle i32 %x, 100
%cmp = icmp sgt i32 %x, 300
%. = select i1 %cmp, i32 1, i32 2
ret i32 %.
}
attributes #1 = { noinline }
Reviewers: davide, sanjoy, efriedma, dberlin
Reviewed By: davide, dberlin
Subscribers: mcrosier, gberry, mssimpso, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D36656
llvm-svn: 315288
Diffstat (limited to 'llvm/test/Transforms/SCCP/ip-constan-ranges.ll')
| -rw-r--r-- | llvm/test/Transforms/SCCP/ip-constan-ranges.ll | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/llvm/test/Transforms/SCCP/ip-constan-ranges.ll b/llvm/test/Transforms/SCCP/ip-constan-ranges.ll new file mode 100644 index 00000000000..bd6da1f4d34 --- /dev/null +++ b/llvm/test/Transforms/SCCP/ip-constan-ranges.ll @@ -0,0 +1,117 @@ +; RUN: opt < %s -ipsccp -S | FileCheck %s + +; 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 +define internal i32 @f1(i32 %a, i32 %b) { +entry: + %cmp.a = icmp sgt i32 %a, 300 + %cmp.b = icmp sgt i32 %b, 300 + %cmp.a2 = icmp ugt i32 %a, 300 + %cmp.b2 = icmp ugt i32 %b, 300 + + %a.1 = select i1 %cmp.a, i32 1, i32 2 + %b.1 = select i1 %cmp.b, i32 1, i32 2 + %a.2 = select i1 %cmp.a2, i32 1, i32 2 + %b.2 = select i1 %cmp.b2, i32 1, i32 2 + %res1 = add i32 %a.1, %b.1 + %res2 = add i32 %a.2, %b.2 + %res3 = add i32 %res1, %res2 + ret i32 %res3 +} + +; Constant range for %x is [47, 302) +; 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 +define internal i32 @f2(i32 %x) { +entry: + %cmp = icmp sgt i32 %x, 300 + %cmp2 = icmp ne i32 %x, 10 + %cmp3 = icmp sge i32 %x, 47 + %cmp4 = icmp ugt i32 %x, 300 + %cmp5 = icmp uge i32 %x, 47 + %res1 = select i1 %cmp, i32 1, i32 2 + %res2 = select i1 %cmp2, i32 3, i32 4 + %res3 = select i1 %cmp3, i32 5, i32 6 + %res4 = select i1 %cmp4, i32 3, i32 4 + %res5 = select i1 %cmp5, i32 5, i32 6 + + %res6 = add i32 %res1, %res2 + %res7 = add i32 %res3, %res4 + %res = add i32 %res6, %res5 + ret i32 %res +} + +define i32 @caller1() { +entry: + %call1 = tail call i32 @f1(i32 1, i32 301) + %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.2 = add nsw i32 %res.1, %call4 + ret i32 %res.2 +} + +; x is overdefined, because constant ranges are only used for parameter +; values. +; CHECK-LABEL: f3 +; CHECK: %cmp = icmp sgt i32 %x, 300 +; CHECK: %res = select i1 %cmp, i32 1, i32 2 +; CHECK: ret i32 %res +define internal i32 @f3(i32 %x) { +entry: + %cmp = icmp sgt i32 %x, 300 + %res = select i1 %cmp, i32 1, i32 2 + ret i32 %res +} + +; The phi node could be converted in a ConstantRange. +define i32 @caller2(i1 %cmp) { +entry: + br i1 %cmp, label %if.true, label %end + +if.true: + br label %end + +end: + %res = phi i32 [ 0, %entry], [ 1, %if.true ] + %call1 = tail call i32 @f3(i32 %res) + ret i32 %call1 +} + +; CHECK-LABEL: f4 +; CHECK: %cmp = icmp sgt i32 %x, 300 +; CHECK: %res = select i1 %cmp, i32 1, i32 2 +; CHECK: ret i32 %res +define internal i32 @f4(i32 %x) { +entry: + %cmp = icmp sgt i32 %x, 300 + %res = select i1 %cmp, i32 1, i32 2 + ret i32 %res +} + +; ICmp could introduce bounds on ConstantRanges. +define i32 @caller3(i32 %x) { +entry: + %cmp = icmp sgt i32 %x, 300 + br i1 %cmp, label %if.true, label %end + +if.true: + %x.1 = tail call i32 @f4(i32 %x) + br label %end + +end: + %res = phi i32 [ 0, %entry], [ %x.1, %if.true ] + ret i32 %res +} |

