1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00
llvm-mirror/test/Transforms/SCCP/ip-constant-ranges.ll
Florian Hahn 0e532fb177 [SCCP] Use ranges for predicate info conditions.
This patch updates the code that deals with conditions from predicate
info to make use of constant ranges.

For ssa_copy instructions inserted by PredicateInfo, we have 2 ranges:
1. The range of the original value.
2. The range imposed by the linked condition.

1. is known, 2. can be determined using makeAllowedICmpRegion. The
intersection of those ranges is the range for the copy.

With this patch, we get a nice increase in the number of instructions
eliminated by both SCCP and IPSCCP for some benchmarks:

For MultiSource, SPEC2000 & SPEC2006:

Tests: 237
Same hash: 170 (filtered out)
Remaining: 67
Metric: sccp.NumInstRemoved
Program                                        base    patch   diff
 test-suite...Source/Benchmarks/sim/sim.test    10.00   71.00  610.0%
 test-suite...CFP2000/177.mesa/177.mesa.test   361.00  1626.00 350.4%
 test-suite...encode/alacconvert-encode.test   141.00  602.00  327.0%
 test-suite...decode/alacconvert-decode.test   141.00  602.00  327.0%
 test-suite...CI_Purple/SMG2000/smg2000.test   1639.00 4093.00 149.7%
 test-suite...peg2/mpeg2dec/mpeg2decode.test    75.00  163.00  117.3%
 test-suite...T2006/401.bzip2/401.bzip2.test   358.00  513.00  43.3%
 test-suite...rks/FreeBench/pifft/pifft.test    11.00   15.00  36.4%
 test-suite...langs-C/unix-tbl/unix-tbl.test     4.00    5.00  25.0%
 test-suite...lications/sqlite3/sqlite3.test   541.00  667.00  23.3%
 test-suite.../CINT2000/254.gap/254.gap.test   243.00  299.00  23.0%
 test-suite...ks/Prolangs-C/agrep/agrep.test    25.00   29.00  16.0%
 test-suite...marks/7zip/7zip-benchmark.test   1135.00 1304.00 14.9%
 test-suite...lications/ClamAV/clamscan.test   1105.00 1268.00 14.8%
 test-suite...urce/Applications/lua/lua.test   398.00  436.00   9.5%

Metric: sccp.IPNumInstRemoved
Program                                        base   patch   diff
 test-suite...C/CFP2000/179.art/179.art.test     1.00   3.00  200.0%
 test-suite...006/447.dealII/447.dealII.test   429.00 1056.00 146.2%
 test-suite...nch/fourinarow/fourinarow.test     3.00   7.00  133.3%
 test-suite...CI_Purple/SMG2000/smg2000.test   818.00 1748.00 113.7%
 test-suite...ks/McCat/04-bisect/bisect.test     3.00   5.00  66.7%
 test-suite...CFP2000/177.mesa/177.mesa.test   165.00 255.00  54.5%
 test-suite...ediabench/gsm/toast/toast.test    18.00  27.00  50.0%
 test-suite...telecomm-gsm/telecomm-gsm.test    18.00  27.00  50.0%
 test-suite...ks/Prolangs-C/agrep/agrep.test    24.00  35.00  45.8%
 test-suite...TimberWolfMC/timberwolfmc.test    43.00  62.00  44.2%
 test-suite...encode/alacconvert-encode.test    46.00  66.00  43.5%
 test-suite...decode/alacconvert-decode.test    46.00  66.00  43.5%
 test-suite...langs-C/unix-tbl/unix-tbl.test    12.00  17.00  41.7%
 test-suite...peg2/mpeg2dec/mpeg2decode.test    31.00  41.00  32.3%
 test-suite.../CINT2000/254.gap/254.gap.test   117.00 154.00  31.6%

Reviewers: efriedma, davide

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D76611
2020-04-07 11:09:18 +01:00

239 lines
5.9 KiB
LLVM

; RUN: opt < %s -ipsccp -S | FileCheck %s
; Constant range for %a is [1, 48) and for %b is [301, 1000)
; CHECK-LABEL: f1
; CHECK: ret i32 undef
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: %res4 = select i1 %cmp4, i32 3, i32 4
; 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
%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.1 = add nsw i32 12, %call3
%res.2 = add nsw i32 %res.1, %call4
ret i32 %res.2
}
; CHECK-LABEL: f3
; CHECK-LABEL: entry:
; CHECK: ret i32 undef
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 2
}
; CHECK-LABEL: f4
; CHECK: ret i32 undef
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 introduces bounds on ConstantRanges.
define i32 @caller3(i32 %x) {
; CHECK-LABEL: define i32 @caller3(i32 %x)
; CHECK-LABEL: end:
; CHECK-NEXT: %res = phi i32 [ 0, %entry ], [ 1, %if.true ]
; CHECK-NEXT: ret i32 %res
;
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
}
; Check to make sure we do not attempt to access lattice values in unreachable
; blocks.
define i32 @test_unreachable() {
entry:
call i1 @test_unreachable_callee(i32 1)
call i1 @test_unreachable_callee(i32 2)
ret i32 1
}
define internal i1 @test_unreachable_callee(i32 %a) {
entry:
ret i1 true
unreachablebb:
%cmp = icmp eq i32 undef, %a
unreachable
}
; Check that we do not attempt to get range info for non-integer types and
; crash.
define double @test_struct({ double, double } %test) {
%v = extractvalue { double, double } %test, 0
%r = fmul double %v, %v
ret double %r
}
; Constant range for %x is [47, 302)
; CHECK-LABEL: @f5
; CHECK-NEXT: entry:
; CHECK-NEXT: %cmp = icmp sgt i32 %x, undef
; CHECK-NEXT: %cmp2 = icmp ne i32 undef, %x
; CHECK-NEXT: %res1 = select i1 %cmp, i32 1, i32 2
; CHECK-NEXT: %res2 = select i1 %cmp2, i32 3, i32 4
; CHECK-NEXT: %res = add i32 %res1, %res2
; CHECK-NEXT: ret i32 %res
define internal i32 @f5(i32 %x) {
entry:
%cmp = icmp sgt i32 %x, undef
%cmp2 = icmp ne i32 undef, %x
%res1 = select i1 %cmp, i32 1, i32 2
%res2 = select i1 %cmp2, i32 3, i32 4
%res = add i32 %res1, %res2
ret i32 %res
}
define i32 @caller4() {
entry:
%call1 = tail call i32 @f5(i32 47)
%call2 = tail call i32 @f5(i32 301)
%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
}
define internal i32 @callee6.1(i32 %i) {
; CHECK-LABEL: define internal i32 @callee6.1(
; CHECK-NEXT: %res = call i32 @callee6.2(i32 %i)
; CHECK-NEXT: ret i32 undef
;
%res = call i32 @callee6.2(i32 %i)
ret i32 %res
}
define internal i32 @callee6.2(i32 %i) {
; CHECK-LABEL: define internal i32 @callee6.2(i32 %i) {
; CHECK-NEXT: br label %if.then
; CHECK-LABEL: if.then:
; CHECK-NEXT: ret i32 undef
;
%cmp = icmp ne i32 %i, 0
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
ret i32 1
if.else: ; preds = %entry
ret i32 2
}
define i32 @caller6() {
; CHECK-LABEL: define i32 @caller6() {
; CHECK-NEXT: %call.1 = call i32 @callee6.1(i32 30)
; CHECK-NEXT: %call.2 = call i32 @callee6.1(i32 43)
; CHECK-NEXT: ret i32 2
;
%call.1 = call i32 @callee6.1(i32 30)
%call.2 = call i32 @callee6.1(i32 43)
%res = add i32 %call.1, %call.2
ret i32 %res
}