[llvm-dev] [RFC] Improving integer divide optimization (related to D12082)
Steve King via llvm-dev
llvm-dev at lists.llvm.org
Thu Aug 20 11:46:57 PDT 2015
On Thu, Aug 20, 2015 at 9:59 AM, Mehdi Amini <mehdi.amini at apple.com> wrote:
> If you want the attributes, I think you should pass the attributes and not the whole Function.
OK.
> Did you consider what I suggested, i.e. inverting the order of the two tests?
I don't see this suggestion in our thread.
> Thinking about it more, I even think than removing the first test entirely would even be nicer here.
> The default implementation for BuildSDIVPow2() would be:
>
> virtual SDValue BuildSDIVPow2(SDValue N) {
> bool MinSize = …. // choose a default, target can override anyway
> if (TLI.isIntDivCheap(N->getValueType(0), MinSize))
> return N;
> return SDValue();
> }
>
> I believe this would preserve the current default behavior and leave targets the ability to override as much as they want.
>
Nice. visitSDIV() and visitUDIV() still call isIntDivCheap() for
non-power-of-2 cases. Passing attributes to isIntDivCheap() to enable
a smart check is still desirable, but you eliminated the need for a
power-of-2 flag.
Today's TargetLowering default:
virtual SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor,
SelectionDAG &DAG,
std::vector<SDNode *> *Created) const {
return SDValue();
}
New default with your approach and Fn attributes:
virtual SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor,
SelectionDAG &DAG,
std::vector<SDNode *> *Created) const {
AttributeSet Attr = DAG.getMachineFunction().getFunction()->getAttributes();
if (TLI.isIntDivCheap(N->getValueType(0), Attr))
return N;
return SDValue();
}
virtual bool isIntDivCheap(EVT VT, AttributeSet Attr) const {
return false;
}
X86 is the only in-tree user, so to preserve today's behavior:
bool X86TargetLowering::isIntDivCheap(EVT VT, AttributeSet Attr) const {
bool OptSize = Attr.hasAttribute(AttributeSet::FunctionIndex,
Attribute::MinSize)
return OptSize && !VT.isVector();
}
More information about the llvm-dev
mailing list