diff options
author | Jim Lin <jim@andestech.com> | 2025-10-14 08:45:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-14 08:45:00 +0800 |
commit | 1c00a001f605eb87b54d47ce9d7992f7021474b4 (patch) | |
tree | 1742fc2e7e5de0f230ea5f10d0696fc7ee6b8768 /llvm/lib/Target | |
parent | 3e22438320003f0c2ed8a8d10b17071d6a093325 (diff) | |
download | llvm-1c00a001f605eb87b54d47ce9d7992f7021474b4.zip llvm-1c00a001f605eb87b54d47ce9d7992f7021474b4.tar.gz llvm-1c00a001f605eb87b54d47ce9d7992f7021474b4.tar.bz2 |
[RISCV] Merge ADDI and SIGN_EXTEND_INREG to ADDIW during selectSETCC. (#162614)
That we can merge ADDI with its LHS to ADDIW if its LHS is a
SIGN_EXTEND_INREG.
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp index 437022f..974252a 100644 --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp @@ -3353,14 +3353,20 @@ bool RISCVDAGToDAGISel::selectSETCC(SDValue N, ISD::CondCode ExpectedCCVal, 0); return true; } - // If the RHS is [-2047,2048], we can use addi with -RHS to produce 0 if the - // LHS is equal to the RHS and non-zero otherwise. + // If the RHS is [-2047,2048], we can use addi/addiw with -RHS to produce 0 + // if the LHS is equal to the RHS and non-zero otherwise. if (isInt<12>(CVal) || CVal == 2048) { - Val = SDValue( - CurDAG->getMachineNode( - RISCV::ADDI, DL, N->getValueType(0), LHS, - CurDAG->getSignedTargetConstant(-CVal, DL, N->getValueType(0))), - 0); + unsigned Opc = RISCV::ADDI; + if (LHS.getOpcode() == ISD::SIGN_EXTEND_INREG && + cast<VTSDNode>(LHS.getOperand(1))->getVT() == MVT::i32) { + Opc = RISCV::ADDIW; + LHS = LHS.getOperand(0); + } + + Val = SDValue(CurDAG->getMachineNode(Opc, DL, N->getValueType(0), LHS, + CurDAG->getSignedTargetConstant( + -CVal, DL, N->getValueType(0))), + 0); return true; } if (isPowerOf2_64(CVal) && Subtarget->hasStdExtZbs()) { |