Skip to content

Commit

Permalink
[RISCV][NFC] Make Zb* instruction naming match the convention used el…
Browse files Browse the repository at this point in the history
…sewhere in the RISC-V backend

Where the instruction mnemonic contains a dot, we name the corresponding
instruction in the .td file using a _ in the place of the dot. e.g. LR_W
rather than LRW. This commit updates RISCVInstrInfoZb.td to follow that
convention.
  • Loading branch information
asb committed Jan 28, 2022
1 parent 5f856c5 commit 588f121
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 97 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Expand Up @@ -2266,8 +2266,8 @@ void RISCVAsmParser::emitLoadImm(MCRegister DestReg, int64_t Value,
if (Inst.Opc == RISCV::LUI) {
emitToStreamer(
Out, MCInstBuilder(RISCV::LUI).addReg(DestReg).addImm(Inst.Imm));
} else if (Inst.Opc == RISCV::ADDUW) {
emitToStreamer(Out, MCInstBuilder(RISCV::ADDUW)
} else if (Inst.Opc == RISCV::ADD_UW) {
emitToStreamer(Out, MCInstBuilder(RISCV::ADD_UW)
.addReg(DestReg)
.addReg(SrcReg)
.addReg(RISCV::X0));
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
Expand Up @@ -31,7 +31,7 @@ static int getInstSeqCost(RISCVMatInt::InstSeq &Res, bool HasRVC) {
case RISCV::LUI:
Compressed = isInt<6>(Instr.Imm);
break;
case RISCV::ADDUW:
case RISCV::ADD_UW:
Compressed = false;
break;
}
Expand Down Expand Up @@ -123,18 +123,19 @@ static void generateInstSeqImpl(int64_t Val,
}
}

// Try to use SLLIUW for Hi52 when it is uint32 but not int32.
// Try to use SLLI_UW for Hi52 when it is uint32 but not int32.
if (isUInt<32>((uint64_t)Hi52) && !isInt<32>((uint64_t)Hi52) &&
ActiveFeatures[RISCV::FeatureStdExtZba]) {
// Use LUI+ADDI or LUI to compose, then clear the upper 32 bits with SLLIUW.
// Use LUI+ADDI or LUI to compose, then clear the upper 32 bits with
// SLLI_UW.
Hi52 = ((uint64_t)Hi52) | (0xffffffffull << 32);
Unsigned = true;
}

generateInstSeqImpl(Hi52, ActiveFeatures, Res);

if (Unsigned)
Res.push_back(RISCVMatInt::Inst(RISCV::SLLIUW, ShiftAmount));
Res.push_back(RISCVMatInt::Inst(RISCV::SLLI_UW, ShiftAmount));
else
Res.push_back(RISCVMatInt::Inst(RISCV::SLLI, ShiftAmount));
if (Lo12)
Expand Down Expand Up @@ -210,7 +211,7 @@ InstSeq generateInstSeq(int64_t Val, const FeatureBitset &ActiveFeatures) {
uint64_t LeadingOnesVal = Val | maskLeadingOnes<uint64_t>(LeadingZeros);
TmpSeq.clear();
generateInstSeqImpl(LeadingOnesVal, ActiveFeatures, TmpSeq);
TmpSeq.push_back(RISCVMatInt::Inst(RISCV::ADDUW, 0));
TmpSeq.push_back(RISCVMatInt::Inst(RISCV::ADD_UW, 0));

// Keep the new sequence if it is an improvement.
if (TmpSeq.size() < Res.size()) {
Expand Down
28 changes: 14 additions & 14 deletions llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Expand Up @@ -166,8 +166,8 @@ static SDNode *selectImm(SelectionDAG *CurDAG, const SDLoc &DL, const MVT VT,
SDValue SDImm = CurDAG->getTargetConstant(Inst.Imm, DL, XLenVT);
if (Inst.Opc == RISCV::LUI)
Result = CurDAG->getMachineNode(RISCV::LUI, DL, XLenVT, SDImm);
else if (Inst.Opc == RISCV::ADDUW)
Result = CurDAG->getMachineNode(RISCV::ADDUW, DL, XLenVT, SrcReg,
else if (Inst.Opc == RISCV::ADD_UW)
Result = CurDAG->getMachineNode(RISCV::ADD_UW, DL, XLenVT, SrcReg,
CurDAG->getRegister(RISCV::X0, XLenVT));
else if (Inst.Opc == RISCV::SH1ADD || Inst.Opc == RISCV::SH2ADD ||
Inst.Opc == RISCV::SH3ADD)
Expand Down Expand Up @@ -775,10 +775,10 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
C1 == (maskTrailingOnes<uint64_t>(XLen - (C2 + C3)) << C2)) {
// Use slli.uw when possible.
if ((XLen - (C2 + C3)) == 32 && Subtarget->hasStdExtZba()) {
SDNode *SLLIUW =
CurDAG->getMachineNode(RISCV::SLLIUW, DL, XLenVT, X,
SDNode *SLLI_UW =
CurDAG->getMachineNode(RISCV::SLLI_UW, DL, XLenVT, X,
CurDAG->getTargetConstant(C2, DL, XLenVT));
ReplaceNode(Node, SLLIUW);
ReplaceNode(Node, SLLI_UW);
return;
}

Expand Down Expand Up @@ -1811,7 +1811,7 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits) const {
case RISCV::CLZW:
case RISCV::CTZW:
case RISCV::CPOPW:
case RISCV::SLLIUW:
case RISCV::SLLI_UW:
case RISCV::FCVT_H_W:
case RISCV::FCVT_H_WU:
case RISCV::FCVT_S_W:
Expand All @@ -1830,20 +1830,20 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits) const {
if (Bits < (64 - countLeadingZeros(User->getConstantOperandVal(1))))
return false;
break;
case RISCV::SEXTB:
case RISCV::SEXT_B:
if (Bits < 8)
return false;
break;
case RISCV::SEXTH:
case RISCV::ZEXTH_RV32:
case RISCV::ZEXTH_RV64:
case RISCV::SEXT_H:
case RISCV::ZEXT_H_RV32:
case RISCV::ZEXT_H_RV64:
if (Bits < 16)
return false;
break;
case RISCV::ADDUW:
case RISCV::SH1ADDUW:
case RISCV::SH2ADDUW:
case RISCV::SH3ADDUW:
case RISCV::ADD_UW:
case RISCV::SH1ADD_UW:
case RISCV::SH2ADD_UW:
case RISCV::SH3ADD_UW:
// The first operand to add.uw/shXadd.uw is implicitly zero extended from
// 32 bits.
if (UI.getOperandNo() != 0 || Bits < 32)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Expand Up @@ -654,8 +654,8 @@ void RISCVInstrInfo::movImm(MachineBasicBlock &MBB,
BuildMI(MBB, MBBI, DL, get(RISCV::LUI), Result)
.addImm(Inst.Imm)
.setMIFlag(Flag);
} else if (Inst.Opc == RISCV::ADDUW) {
BuildMI(MBB, MBBI, DL, get(RISCV::ADDUW), Result)
} else if (Inst.Opc == RISCV::ADD_UW) {
BuildMI(MBB, MBBI, DL, get(RISCV::ADD_UW), Result)
.addReg(SrcReg, RegState::Kill)
.addReg(RISCV::X0)
.setMIFlag(Flag);
Expand Down

0 comments on commit 588f121

Please sign in to comment.