diff options
author | Owen Anderson <resistor@mac.com> | 2010-09-28 18:32:13 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2010-09-28 18:32:13 +0000 |
commit | 88af7d00fc2584217465f07e1f0cc5bbf63d6592 (patch) | |
tree | d9c37203e2a1fbb71c6950a5f099e6b0e9138a89 /llvm/lib | |
parent | 5154ee0bca72c6decffab014163d61c0f5a526c6 (diff) | |
download | bcm5719-llvm-88af7d00fc2584217465f07e1f0cc5bbf63d6592.tar.gz bcm5719-llvm-88af7d00fc2584217465f07e1f0cc5bbf63d6592.zip |
Part one of switching to using a more sane heuristic for determining if-conversion profitability.
Rather than having arbitrary cutoffs, actually try to cost model the conversion.
For now, the constants are tuned to more or less match our existing behavior, but these will be
changed to reflect realistic values as this work proceeds.
llvm-svn: 114973
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/IfConversion.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp | 34 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/ARMBaseInstrInfo.h | 8 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/Thumb2InstrInfo.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/Thumb2InstrInfo.h | 5 |
5 files changed, 33 insertions, 47 deletions
diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp index d73cd538f32..c9c56dd86d2 100644 --- a/llvm/lib/CodeGen/IfConversion.cpp +++ b/llvm/lib/CodeGen/IfConversion.cpp @@ -191,13 +191,13 @@ namespace { void MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI, bool AddEdges = true); bool MeetIfcvtSizeLimit(MachineBasicBlock &BB, unsigned Size) const { - return Size > 0 && TII->isProfitableToIfCvt(BB, Size); + return Size > 0 && TII->isProfitableToIfCvt(BB, Size, 0.5); } bool MeetIfcvtSizeLimit(MachineBasicBlock &TBB, unsigned TSize, MachineBasicBlock &FBB, unsigned FSize) const { return TSize > 0 && FSize > 0 && - TII->isProfitableToIfCvt(TBB, TSize, FBB, FSize); + TII->isProfitableToIfCvt(TBB, TSize, FBB, FSize, 0.5); } // blockAlwaysFallThrough - Block ends without a terminator. @@ -444,7 +444,7 @@ bool IfConverter::ValidSimple(BBInfo &TrueBBI, unsigned &Dups) const { if (TrueBBI.BB->pred_size() > 1) { if (TrueBBI.CannotBeCopied || - !TII->isProfitableToDupForIfCvt(*TrueBBI.BB, TrueBBI.NonPredSize)) + !TII->isProfitableToDupForIfCvt(*TrueBBI.BB, TrueBBI.NonPredSize, 0.5)) return false; Dups = TrueBBI.NonPredSize; } @@ -481,7 +481,7 @@ bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI, ++Size; } } - if (!TII->isProfitableToDupForIfCvt(*TrueBBI.BB, Size)) + if (!TII->isProfitableToDupForIfCvt(*TrueBBI.BB, Size, 0.5)) return false; Dups = Size; } diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp index 04aeac3b19b..f92317c322c 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -1195,22 +1195,36 @@ bool ARMBaseInstrInfo::isSchedulingBoundary(const MachineInstr *MI, return false; } -bool ARMBaseInstrInfo:: -isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumInstrs) const { +bool ARMBaseInstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB, + unsigned NumInstrs, + float Probability) const { if (!NumInstrs) return false; - if (Subtarget.getCPUString() == "generic") - // Generic (and overly aggressive) if-conversion limits for testing. - return NumInstrs <= 10; - else if (Subtarget.hasV7Ops()) - return NumInstrs <= 3; - return NumInstrs <= 2; + + // Attempt to estimate the relative costs of predication versus branching. + float UnpredCost = Probability * NumInstrs; + UnpredCost += 2.0; // FIXME: Should model a misprediction cost. + + float PredCost = NumInstrs; + + return PredCost < UnpredCost; + } bool ARMBaseInstrInfo:: isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT, - MachineBasicBlock &FMBB, unsigned NumF) const { - return NumT && NumF && NumT <= 2 && NumF <= 2; + MachineBasicBlock &FMBB, unsigned NumF, + float Probability) const { + if (!NumT || !NumF) + return false; + + // Attempt to estimate the relative costs of predication versus branching. + float UnpredCost = Probability * NumT + (1.0 - Probability) * NumF; + UnpredCost += 2.0; // FIXME: Should model a misprediction cost. + + float PredCost = NumT + NumF; + + return PredCost < UnpredCost; } /// getInstrPredicate - If instruction is predicated, returns its predicate diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.h b/llvm/lib/Target/ARM/ARMBaseInstrInfo.h index c4af703e9c1..f6800bb01a4 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.h +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.h @@ -312,13 +312,15 @@ public: const MachineFunction &MF) const; virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, - unsigned NumInstrs) const; + unsigned NumInstrs, float Prob) const; virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB,unsigned NumT, - MachineBasicBlock &FMBB,unsigned NumF) const; + MachineBasicBlock &FMBB,unsigned NumF, + float Probability) const; virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, - unsigned NumInstrs) const { + unsigned NumInstrs, + float Probability) const { return NumInstrs && NumInstrs == 1; } diff --git a/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp b/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp index 09abf1d2484..49f5e4a9509 100644 --- a/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp +++ b/llvm/lib/Target/ARM/Thumb2InstrInfo.cpp @@ -28,16 +28,6 @@ using namespace llvm; -static cl::opt<unsigned> -IfCvtLimit("thumb2-ifcvt-limit", cl::Hidden, - cl::desc("Thumb2 if-conversion limit (default 3)"), - cl::init(3)); - -static cl::opt<unsigned> -IfCvtDiamondLimit("thumb2-ifcvt-diamond-limit", cl::Hidden, - cl::desc("Thumb2 diamond if-conversion limit (default 3)"), - cl::init(3)); - Thumb2InstrInfo::Thumb2InstrInfo(const ARMSubtarget &STI) : ARMBaseInstrInfo(STI), RI(*this, STI) { } @@ -105,21 +95,6 @@ Thumb2InstrInfo::isLegalToSplitMBBAt(MachineBasicBlock &MBB, return llvm::getITInstrPredicate(MBBI, PredReg) == ARMCC::AL; } -bool Thumb2InstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB, - unsigned NumInstrs) const { - return NumInstrs && NumInstrs <= IfCvtLimit; -} - -bool Thumb2InstrInfo:: -isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT, - MachineBasicBlock &FMBB, unsigned NumF) const { - // FIXME: Catch optimization such as: - // r0 = movne - // r0 = moveq - return NumT && NumF && - NumT <= (IfCvtDiamondLimit) && NumF <= (IfCvtDiamondLimit); -} - void Thumb2InstrInfo::copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, unsigned DestReg, unsigned SrcReg, diff --git a/llvm/lib/Target/ARM/Thumb2InstrInfo.h b/llvm/lib/Target/ARM/Thumb2InstrInfo.h index b66be8eac48..9ed7eea7e2d 100644 --- a/llvm/lib/Target/ARM/Thumb2InstrInfo.h +++ b/llvm/lib/Target/ARM/Thumb2InstrInfo.h @@ -38,11 +38,6 @@ public: bool isLegalToSplitMBBAt(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const; - bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumInstrs) const; - - bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumTInstrs, - MachineBasicBlock &FMBB, unsigned NumFInstrs) const; - void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, unsigned DestReg, unsigned SrcReg, |