Skip to content

[RISCV][RFC] Add additional opcodes to RISCVDAGToDAGISel::hasAllNBitUsers #147728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3606,11 +3606,15 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
if (Use.getOperandNo() == 1 && Bits >= Log2_32(Subtarget->getXLen()))
break;
return false;
case RISCV::SLLI:
case RISCV::SLLI: {
// SLLI only uses the lower (XLen - ShAmt) bits.
if (Bits >= Subtarget->getXLen() - User->getConstantOperandVal(1))
uint64_t ShAmt = User->getConstantOperandVal(1);
if (Bits >= Subtarget->getXLen() - ShAmt)
break;
if (hasAllNBitUsers(User, Bits + ShAmt, Depth + 1))
break;
return false;
}
case RISCV::ANDI:
if (Bits >= (unsigned)llvm::bit_width(User->getConstantOperandVal(1)))
break;
Expand All @@ -3621,20 +3625,39 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
break;
[[fallthrough]];
}
case RISCV::COPY:
case RISCV::PHI:
case RISCV::ADD:
case RISCV::ADDI:
case RISCV::AND:
case RISCV::MUL:
case RISCV::OR:
case RISCV::SUB:
case RISCV::XOR:
case RISCV::XORI:
case RISCV::ANDN:
case RISCV::BREV8:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BREV8 and ORC_B are incorrect in RISCVOptWInstrs. We need to round to the nearest byte before doing the recursive call.

case RISCV::CLMUL:
case RISCV::ORC_B:
case RISCV::ORN:
case RISCV::XNOR:
case RISCV::SH1ADD:
case RISCV::SH2ADD:
case RISCV::SH3ADD:
case RISCV::BSETI:
case RISCV::BCLRI:
case RISCV::BINVI:
RecCheck:
if (hasAllNBitUsers(User, Bits, Depth + 1))
break;
return false;
case RISCV::CZERO_EQZ:
case RISCV::CZERO_NEZ:
if (Use.getOperandNo() != 0)
return false;
if (hasAllNBitUsers(User, Bits, Depth + 1))
break;
return false;
case RISCV::SRLI: {
unsigned ShAmt = User->getConstantOperandVal(1);
// If we are shifting right by less than Bits, and users don't demand any
Expand Down Expand Up @@ -3670,6 +3693,10 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
if (Use.getOperandNo() == 0 && Bits >= 32)
break;
return false;
case RISCV::BEXTI:
if (User->getConstantOperandVal(1) >= Bits)
return false;
break;
case RISCV::SB:
if (Use.getOperandNo() == 0 && Bits >= 8)
break;
Expand Down
Loading