mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-01 07:10:37 +00:00
[JumpThread] Enhance finding partial redundant loads by continuing scanning single predecessor
Summary: While scanning predecessors to find an available loaded value, if the predecessor has a single predecessor, we can continue scanning through the single predecessor. Reviewers: mcrosier, rengolin, reames, davidxl, haicheng Reviewed By: rengolin Subscribers: zzheng, llvm-commits Differential Revision: https://reviews.llvm.org/D29200 llvm-svn: 293896
This commit is contained in:
parent
417b2207b8
commit
296a001019
@ -85,7 +85,8 @@ Value *FindAvailableLoadedValue(LoadInst *Load,
|
||||
BasicBlock::iterator &ScanFrom,
|
||||
unsigned MaxInstsToScan = DefMaxInstsToScan,
|
||||
AliasAnalysis *AA = nullptr,
|
||||
bool *IsLoadCSE = nullptr);
|
||||
bool *IsLoadCSE = nullptr,
|
||||
unsigned *NumScanedInst = nullptr);
|
||||
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,8 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load,
|
||||
BasicBlock *ScanBB,
|
||||
BasicBlock::iterator &ScanFrom,
|
||||
unsigned MaxInstsToScan,
|
||||
AliasAnalysis *AA, bool *IsLoadCSE) {
|
||||
AliasAnalysis *AA, bool *IsLoadCSE,
|
||||
unsigned *NumScanedInst) {
|
||||
if (MaxInstsToScan == 0)
|
||||
MaxInstsToScan = ~0U;
|
||||
|
||||
@ -344,6 +345,9 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load,
|
||||
// Restore ScanFrom to expected value in case next test succeeds
|
||||
ScanFrom++;
|
||||
|
||||
if (NumScanedInst)
|
||||
++(*NumScanedInst);
|
||||
|
||||
// Don't scan huge blocks.
|
||||
if (MaxInstsToScan-- == 0)
|
||||
return nullptr;
|
||||
|
@ -982,10 +982,25 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
|
||||
|
||||
// Scan the predecessor to see if the value is available in the pred.
|
||||
BBIt = PredBB->end();
|
||||
Value *PredAvailable = FindAvailableLoadedValue(LI, PredBB, BBIt,
|
||||
DefMaxInstsToScan,
|
||||
nullptr,
|
||||
&IsLoadCSE);
|
||||
unsigned NumScanedInst = 0;
|
||||
Value *PredAvailable =
|
||||
FindAvailableLoadedValue(LI, PredBB, BBIt, DefMaxInstsToScan, nullptr,
|
||||
&IsLoadCSE, &NumScanedInst);
|
||||
|
||||
// If PredBB has a single predecessor, continue scanning through the single
|
||||
// precessor.
|
||||
BasicBlock *SinglePredBB = PredBB;
|
||||
while (!PredAvailable && SinglePredBB && BBIt == SinglePredBB->begin() &&
|
||||
NumScanedInst < DefMaxInstsToScan) {
|
||||
SinglePredBB = SinglePredBB->getSinglePredecessor();
|
||||
if (SinglePredBB) {
|
||||
BBIt = SinglePredBB->end();
|
||||
PredAvailable = FindAvailableLoadedValue(
|
||||
LI, SinglePredBB, BBIt, (DefMaxInstsToScan - NumScanedInst),
|
||||
nullptr, &IsLoadCSE, &NumScanedInst);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PredAvailable) {
|
||||
OneUnavailablePred = PredBB;
|
||||
continue;
|
||||
|
@ -302,6 +302,85 @@ ret2:
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @fn_SinglePred(i1 %c2,i64* %P) {
|
||||
; CHECK-LABEL: @fn_SinglePred
|
||||
; CHECK-LABEL: entry:
|
||||
; CHECK: %[[L1:.*]] = load i64, i64* %P
|
||||
; CHECK: br i1 %c, label %cond3, label %cond1
|
||||
; CHECK-LABEL: cond2:
|
||||
; CHECK-NOT: load
|
||||
; CHECK: %[[PHI:.*]] = phi i64 [ %[[L1]], %cond1 ]
|
||||
; CHECK: call void @fn2(i64 %[[PHI]])
|
||||
; CHECK: br label %end
|
||||
; CHECK-LABEL: cond3:
|
||||
; CHECK: call void @fn2(i64 %l1)
|
||||
; CHECK: call void @fn3(i64 %l1)
|
||||
|
||||
entry:
|
||||
%l1 = load i64, i64* %P
|
||||
%c = icmp eq i64 %l1, 0
|
||||
br i1 %c, label %cond2, label %cond1
|
||||
|
||||
cond1:
|
||||
br i1 %c2, label %cond2, label %end
|
||||
|
||||
cond2:
|
||||
%l2 = load i64, i64* %P
|
||||
call void @fn2(i64 %l2)
|
||||
%c3 = icmp eq i64 %l2, 0
|
||||
br i1 %c3, label %cond3, label %end
|
||||
|
||||
cond3:
|
||||
call void @fn3(i64 %l2)
|
||||
br label %end
|
||||
|
||||
end:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define i32 @fn_SinglePredMultihop(i1 %c1, i1 %c2,i64* %P) {
|
||||
; CHECK-LABEL: @fn_SinglePredMultihop
|
||||
; CHECK-LABEL: entry:
|
||||
; CHECK: %[[L1:.*]] = load i64, i64* %P
|
||||
; CHECK: br i1 %c0, label %cond3, label %cond0
|
||||
; CHECK-LABEL: cond2:
|
||||
; CHECK-NOT: load
|
||||
; CHECK: %[[PHI:.*]] = phi i64 [ %[[L1]], %cond1 ]
|
||||
; CHECK: call void @fn2(i64 %[[PHI]])
|
||||
; CHECK: br label %end
|
||||
; CHECK-LABEL: cond3:
|
||||
; CHECK: call void @fn2(i64 %l1)
|
||||
; CHECK: call void @fn3(i64 %l1)
|
||||
|
||||
entry:
|
||||
%l1 = load i64, i64* %P
|
||||
%c0 = icmp eq i64 %l1, 0
|
||||
br i1 %c0, label %cond2, label %cond0
|
||||
|
||||
cond0:
|
||||
br i1 %c1, label %cond1, label %end
|
||||
|
||||
cond1:
|
||||
br i1 %c2, label %cond2, label %end
|
||||
|
||||
cond2:
|
||||
%l2 = load i64, i64* %P
|
||||
call void @fn2(i64 %l2)
|
||||
%c3 = icmp eq i64 %l2, 0
|
||||
br i1 %c3, label %cond3, label %end
|
||||
|
||||
cond3:
|
||||
call void @fn3(i64 %l2)
|
||||
br label %end
|
||||
|
||||
end:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @fn2(i64)
|
||||
declare void @fn3(i64)
|
||||
|
||||
|
||||
!0 = !{!3, !3, i64 0}
|
||||
!1 = !{!"omnipotent char", !2}
|
||||
!2 = !{!"Simple C/C++ TBAA"}
|
||||
|
Loading…
Reference in New Issue
Block a user