summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorHaicheng Wu <haicheng@codeaurora.org>2016-03-28 18:17:07 +0000
committerHaicheng Wu <haicheng@codeaurora.org>2016-03-28 18:17:07 +0000
commit6a6bc750d5ba2a37438607e360346443268fe8bc (patch)
tree6ac4ffbc6639b2fbd6ac9079d25c5ee3a2121f83 /llvm/lib/Target
parentba85781f5846d156ff867340a203856aa1957dd6 (diff)
downloadbcm5719-llvm-6a6bc750d5ba2a37438607e360346443268fe8bc.tar.gz
bcm5719-llvm-6a6bc750d5ba2a37438607e360346443268fe8bc.zip
[AArch64] Do not lower scalar sdiv/udiv to a shifts + mul sequence when optimizing for minsize
Mimic what x86 does when optimizing sdiv/udiv for minsize. llvm-svn: 264606
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/AArch64/AArch64ISelLowering.cpp17
-rw-r--r--llvm/lib/Target/AArch64/AArch64ISelLowering.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index c35fa4df757..a262b1d2b3f 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -7516,6 +7516,10 @@ SDValue
AArch64TargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
SelectionDAG &DAG,
std::vector<SDNode *> *Created) const {
+ AttributeSet Attr = DAG.getMachineFunction().getFunction()->getAttributes();
+ if (isIntDivCheap(N->getValueType(0), Attr))
+ return SDValue(N,0); // Lower SDIV as SDIV
+
// fold (sdiv X, pow2)
EVT VT = N->getValueType(0);
if ((VT != MVT::i32 && VT != MVT::i64) ||
@@ -10298,3 +10302,16 @@ void AArch64TargetLowering::insertCopiesSplitCSR(
.addReg(NewVR);
}
}
+
+bool AArch64TargetLowering::isIntDivCheap(EVT VT, AttributeSet Attr) const {
+ // Integer division on AArch64 is expensive. However, when aggressively
+ // optimizing for code size, we prefer to use a div instruction, as it is
+ // usually smaller than the alternative sequence.
+ // The exception to this is vector division. Since AArch64 doesn't have vector
+ // integer division, leaving the division as-is is a loss even in terms of
+ // size, because it will have to be scalarized, while the alternative code
+ // sequence can be performed in vector form.
+ bool OptSize =
+ Attr.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize);
+ return OptSize && !VT.isVector();
+}
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.h b/llvm/lib/Target/AArch64/AArch64ISelLowering.h
index 20c468e08de..13eba096142 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -378,6 +378,8 @@ public:
return AArch64::X1;
}
+ bool isIntDivCheap(EVT VT, AttributeSet Attr) const override;
+
bool isCheapToSpeculateCttz() const override {
return true;
}
OpenPOWER on IntegriCloud