Skip to content

Commit 2282d4f

Browse files
authored
[ISel/RISCV] Improve code in lowerFCOPYSIGN (NFC) (#146061)
1 parent 9df1c81 commit 2282d4f

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6848,32 +6848,32 @@ static SDValue lowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG,
68486848
SDLoc DL(Op);
68496849

68506850
// Get sign bit into an integer value.
6851-
SDValue SignAsInt;
68526851
unsigned SignSize = Sign.getValueSizeInBits();
6853-
if (SignSize == Subtarget.getXLen()) {
6854-
SignAsInt = DAG.getNode(ISD::BITCAST, DL, XLenVT, Sign);
6855-
} else if (SignSize == 16) {
6856-
SignAsInt = DAG.getNode(RISCVISD::FMV_X_ANYEXTH, DL, XLenVT, Sign);
6857-
} else if (SignSize == 32) {
6858-
SignAsInt = DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, XLenVT, Sign);
6859-
} else if (SignSize == 64) {
6860-
assert(XLenVT == MVT::i32 && "Unexpected type");
6861-
// Copy the upper word to integer.
6862-
SignAsInt = DAG.getNode(RISCVISD::SplitF64, DL, {MVT::i32, MVT::i32}, Sign)
6863-
.getValue(1);
6864-
SignSize = 32;
6865-
} else
6866-
llvm_unreachable("Unexpected sign size");
6852+
SDValue SignAsInt = [&]() {
6853+
if (SignSize == Subtarget.getXLen())
6854+
return DAG.getNode(ISD::BITCAST, DL, XLenVT, Sign);
6855+
switch (SignSize) {
6856+
case 16:
6857+
return DAG.getNode(RISCVISD::FMV_X_ANYEXTH, DL, XLenVT, Sign);
6858+
case 32:
6859+
return DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, XLenVT, Sign);
6860+
case 64: {
6861+
assert(XLenVT == MVT::i32 && "Unexpected type");
6862+
// Copy the upper word to integer.
6863+
SignSize = 32;
6864+
return DAG.getNode(RISCVISD::SplitF64, DL, {MVT::i32, MVT::i32}, Sign)
6865+
.getValue(1);
6866+
}
6867+
default:
6868+
llvm_unreachable("Unexpected sign size");
6869+
}
6870+
}();
68676871

68686872
// Get the signbit at the right position for MagAsInt.
6869-
int ShiftAmount = (int)SignSize - (int)Mag.getValueSizeInBits();
6870-
if (ShiftAmount > 0) {
6871-
SignAsInt = DAG.getNode(ISD::SRL, DL, XLenVT, SignAsInt,
6872-
DAG.getConstant(ShiftAmount, DL, XLenVT));
6873-
} else if (ShiftAmount < 0) {
6874-
SignAsInt = DAG.getNode(ISD::SHL, DL, XLenVT, SignAsInt,
6875-
DAG.getConstant(-ShiftAmount, DL, XLenVT));
6876-
}
6873+
if (int ShiftAmount = (int)SignSize - (int)Mag.getValueSizeInBits())
6874+
SignAsInt = DAG.getNode(ShiftAmount > 0 ? ISD::SRL : ISD::SHL, DL, XLenVT,
6875+
SignAsInt,
6876+
DAG.getConstant(std::abs(ShiftAmount), DL, XLenVT));
68776877

68786878
// Mask the sign bit and any bits above it. The extra bits will be dropped
68796879
// when we convert back to FP.

0 commit comments

Comments
 (0)