mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-25 05:22:04 +00:00
Optimize sext/zext insertion algorithm in back-end.
With this optimization, we will not always insert zext for values crossing basic blocks, but insert sext if the users of a value crossing basic block has preference of sign predicate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218101 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -56,6 +56,28 @@ static bool isUsedOutsideOfDefiningBlock(const Instruction *I) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static ISD::NodeType getPreferredExtendForValue(const Value *V) {
|
||||
// For the users of the source value being used for compare instruction, if
|
||||
// the number of signed predicate is greater than unsigned predicate, we
|
||||
// prefer to use SIGN_EXTEND.
|
||||
//
|
||||
// With this optimization, we would be able to reduce some redundant sign or
|
||||
// zero extension instruction, and eventually more machine CSE opportunities
|
||||
// can be exposed.
|
||||
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
|
||||
unsigned NumOfSigned = 0, NumOfUnsigned = 0;
|
||||
for (const User *U : V->users()) {
|
||||
if (const auto *CI = dyn_cast<CmpInst>(U)) {
|
||||
NumOfSigned += CI->isSigned();
|
||||
NumOfUnsigned += CI->isUnsigned();
|
||||
}
|
||||
}
|
||||
if (NumOfSigned > NumOfUnsigned)
|
||||
ExtendKind = ISD::SIGN_EXTEND;
|
||||
|
||||
return ExtendKind;
|
||||
}
|
||||
|
||||
void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
|
||||
SelectionDAG *DAG) {
|
||||
const TargetLowering *TLI = TM.getSubtargetImpl()->getTargetLowering();
|
||||
@@ -182,6 +204,9 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decide the preferred extend type for a value.
|
||||
PreferredExtendType[I] = getPreferredExtendForValue(I);
|
||||
}
|
||||
|
||||
// Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This
|
||||
|
||||
Reference in New Issue
Block a user