summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@codeaurora.org>2016-08-26 18:05:50 +0000
committerChad Rosier <mcrosier@codeaurora.org>2016-08-26 18:05:50 +0000
commit58f505ba24761c22314a85874580679c209388b5 (patch)
tree92ddf57be5a42a55d81305cb99fa1025242bdf06 /llvm/lib
parentf4e1661bd8998211fdbaaa3539cb507e0e2d13e7 (diff)
downloadbcm5719-llvm-58f505ba24761c22314a85874580679c209388b5.tar.gz
bcm5719-llvm-58f505ba24761c22314a85874580679c209388b5.zip
[AArch64] Avoid materializing constant values when generating csel instructions.
Differential Revision: https://reviews.llvm.org/D23677 llvm-svn: 279849
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/AArch64/AArch64ISelLowering.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 2236071e5ff..fcbc1a7b4fb 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -4036,6 +4036,22 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(ISD::CondCode CC, SDValue LHS,
}
}
+ // Avoid materializing a constant when possible by reusing a known value in
+ // a register. However, don't perform this optimization if the known value
+ // is one, zero or negative one. We can always materialize these values
+ // using CSINC, CSEL and CSINV with wzr/xzr as the FVal, respectively.
+ ConstantSDNode *RHSVal = dyn_cast<ConstantSDNode>(RHS);
+ if (Opcode == AArch64ISD::CSEL && RHSVal && !RHSVal->isOne() &&
+ !RHSVal->isNullValue() && !RHSVal->isAllOnesValue()) {
+ AArch64CC::CondCode AArch64CC = changeIntCCToAArch64CC(CC);
+ // Transform "a == C ? C : x" to "a == C ? a : x" and "a != C ? x : C" to
+ // "a != C ? x : a" to avoid materializing C.
+ if (CTVal && CTVal == RHSVal && AArch64CC == AArch64CC::EQ)
+ TVal = LHS;
+ else if (CFVal && CFVal == RHSVal && AArch64CC == AArch64CC::NE)
+ FVal = LHS;
+ }
+
SDValue CCVal;
SDValue Cmp = getAArch64Cmp(LHS, RHS, CC, CCVal, DAG, dl);
OpenPOWER on IntegriCloud