Skip to content

[RISCV] Fold (fmv_x_h/w (load)) to an integer load. #109900

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

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16984,6 +16984,17 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
return Op0.getOperand(0);
}

if (ISD::isNormalLoad(Op0.getNode()) && Op0.hasOneUse() &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there something here preventing the load from having an offset? I think the answer is that the load must be a vector load, and that we don't have base+offset addressing for that form, but could you add an assert here to confirm the offset is zero?

Copy link
Collaborator Author

@topperc topperc Sep 25, 2024

Choose a reason for hiding this comment

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

I think the offset field in LoadSDNodeonly is only used by pre/post inc/dec loads. RISC-V only uses for some THead extensions. ISD::isNormalLoad checks that the load isUnindexed() so the offset field should be undef.

The immediate offset for scalar loads is represented by a separate ADD node in the base pointer that we pattern match at isel.

cast<LoadSDNode>(Op0)->isSimple()) {
MVT IVT = MVT::getIntegerVT(Op0.getValueSizeInBits());
auto *LN0 = cast<LoadSDNode>(Op0);
SDValue Load =
DAG.getExtLoad(ISD::EXTLOAD, SDLoc(N), VT, LN0->getChain(),
LN0->getBasePtr(), IVT, LN0->getMemOperand());
DAG.ReplaceAllUsesOfValueWith(Op0.getValue(1), Load.getValue(1));
return Load;
}

// This is a target-specific version of a DAGCombine performed in
// DAGCombiner::visitBITCAST. It performs the equivalent of:
// fold (bitconvert (fneg x)) -> (xor (bitconvert x), signbit)
Expand Down
Loading
Loading