Skip to content

Commit

Permalink
[RISCV] Pull APInt/computeKnonwbits specifics out of computeGREVOrGOR…
Browse files Browse the repository at this point in the history
…C. NFC

This function now takes a uint64_t instead of an APInt. The caller
is responsible for masking the shift amount, extracting and inserting
into the KnownBits APInts, and inverting to compute zeros.

This is less code and cleaner division of responsibilities.
  • Loading branch information
topperc committed Mar 29, 2022
1 parent b316126 commit 45e85fe
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Expand Up @@ -8914,19 +8914,11 @@ bool RISCVTargetLowering::targetShrinkDemandedConstant(
return UseMask(NewMask);
}

static void computeGREVOrGORC(APInt &Src, unsigned ShAmt, bool IsGORC,
bool ComputeZeros = false) {
static uint64_t computeGREVOrGORC(uint64_t x, unsigned ShAmt, bool IsGORC) {
static const uint64_t GREVMasks[] = {
0x5555555555555555ULL, 0x3333333333333333ULL, 0x0F0F0F0F0F0F0F0FULL,
0x00FF00FF00FF00FFULL, 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL};

ShAmt &= Src.getBitWidth() - 1;
uint64_t x = Src.getZExtValue();

// To compute zeros, we need to invert the value and invert it back after.
if (ComputeZeros)
x = ~x;

for (unsigned Stage = 0; Stage != 6; ++Stage) {
unsigned Shift = 1 << Stage;
if (ShAmt & Shift) {
Expand All @@ -8938,10 +8930,7 @@ static void computeGREVOrGORC(APInt &Src, unsigned ShAmt, bool IsGORC,
}
}

if (ComputeZeros)
x = ~x;

Src = x;
return x;
}

void RISCVTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
Expand Down Expand Up @@ -9010,11 +8999,12 @@ void RISCVTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
case RISCVISD::GORC: {
if (auto *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
Known = DAG.computeKnownBits(Op.getOperand(0), Depth + 1);
unsigned ShAmt = C->getZExtValue();
unsigned ShAmt = C->getZExtValue() & (Known.getBitWidth() - 1);
bool IsGORC = Op.getOpcode() == RISCVISD::GORC;
computeGREVOrGORC(Known.Zero, ShAmt, IsGORC,
/*ComputeZeros*/ true);
computeGREVOrGORC(Known.One, ShAmt, IsGORC);
// To compute zeros, we need to invert the value and invert it back after.
Known.Zero =
~computeGREVOrGORC(~Known.Zero.getZExtValue(), ShAmt, IsGORC);
Known.One = computeGREVOrGORC(Known.One.getZExtValue(), ShAmt, IsGORC);
}
break;
}
Expand Down

0 comments on commit 45e85fe

Please sign in to comment.