[llvm] e109ce9 - [NFC][SVE] Refactor SelectSVEAddSubImm to match SelectSVECpyDupImm.
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 25 08:16:33 PST 2022
Author: Paul Walker
Date: 2022-02-25T16:12:35Z
New Revision: e109ce91b8b47fc34fb1301d89b1b8c04b27616b
URL: https://github.com/llvm/llvm-project/commit/e109ce91b8b47fc34fb1301d89b1b8c04b27616b
DIFF: https://github.com/llvm/llvm-project/commit/e109ce91b8b47fc34fb1301d89b1b8c04b27616b.diff
LOG: [NFC][SVE] Refactor SelectSVEAddSubImm to match SelectSVECpyDupImm.
They're equivalent other than one is signed and the other unsigned.
Added:
Modified:
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 8fcf4dd2199a..01dc1607b079 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -3132,46 +3132,41 @@ bool AArch64DAGToDAGISel::SelectCMP_SWAP(SDNode *N) {
return true;
}
-bool AArch64DAGToDAGISel::SelectSVEAddSubImm(SDValue N, MVT VT, SDValue &Imm, SDValue &Shift) {
- if (auto CNode = dyn_cast<ConstantSDNode>(N)) {
- const int64_t ImmVal = CNode->getSExtValue();
- SDLoc DL(N);
+bool AArch64DAGToDAGISel::SelectSVEAddSubImm(SDValue N, MVT VT, SDValue &Imm,
+ SDValue &Shift) {
+ if (!isa<ConstantSDNode>(N))
+ return false;
- switch (VT.SimpleTy) {
- case MVT::i8:
- // Can always select i8s, no shift, mask the immediate value to
- // deal with sign-extended value from lowering.
+ SDLoc DL(N);
+ uint64_t Val = cast<ConstantSDNode>(N)
+ ->getAPIntValue()
+ .truncOrSelf(VT.getFixedSizeInBits())
+ .getZExtValue();
+
+ switch (VT.SimpleTy) {
+ case MVT::i8:
+ // All immediates are supported.
+ Shift = CurDAG->getTargetConstant(0, DL, MVT::i32);
+ Imm = CurDAG->getTargetConstant(Val, DL, MVT::i32);
+ return true;
+ case MVT::i16:
+ case MVT::i32:
+ case MVT::i64:
+ // Support 8bit unsigned immediates.
+ if (Val <= 255) {
Shift = CurDAG->getTargetConstant(0, DL, MVT::i32);
- Imm = CurDAG->getTargetConstant(ImmVal & 0xFF, DL, MVT::i32);
+ Imm = CurDAG->getTargetConstant(Val, DL, MVT::i32);
return true;
- case MVT::i16:
- // i16 values get sign-extended to 32-bits during lowering.
- if ((ImmVal & 0xFF) == ImmVal) {
- Shift = CurDAG->getTargetConstant(0, DL, MVT::i32);
- Imm = CurDAG->getTargetConstant(ImmVal, DL, MVT::i32);
- return true;
- } else if ((ImmVal & 0xFF) == 0) {
- Shift = CurDAG->getTargetConstant(8, DL, MVT::i32);
- Imm = CurDAG->getTargetConstant((ImmVal >> 8) & 0xFF, DL, MVT::i32);
- return true;
- }
- break;
- case MVT::i32:
- case MVT::i64:
- // Range of immediate won't trigger signedness problems for 32/64b.
- if ((ImmVal & 0xFF) == ImmVal) {
- Shift = CurDAG->getTargetConstant(0, DL, MVT::i32);
- Imm = CurDAG->getTargetConstant(ImmVal, DL, MVT::i32);
- return true;
- } else if ((ImmVal & 0xFF00) == ImmVal) {
- Shift = CurDAG->getTargetConstant(8, DL, MVT::i32);
- Imm = CurDAG->getTargetConstant(ImmVal >> 8, DL, MVT::i32);
- return true;
- }
- break;
- default:
- break;
}
+ // Support 16bit unsigned immediates that are a multiple of 256.
+ if (Val <= 65280 && Val % 256 == 0) {
+ Shift = CurDAG->getTargetConstant(8, DL, MVT::i32);
+ Imm = CurDAG->getTargetConstant(Val >> 8, DL, MVT::i32);
+ return true;
+ }
+ break;
+ default:
+ break;
}
return false;
More information about the llvm-commits
mailing list