Skip to content

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Jul 15, 2025

To fold a FrameIndex, we need to teach eliminateFrameIndex to respect the uimm9 range.

…ddrRegImm9.

To fold a FrameIndex, we need to teach eliminateFrameIndex to
respect the uimm9 range.
@topperc
Copy link
Collaborator Author

topperc commented Jul 15, 2025

CC: @ukalappa-mips

@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Craig Topper (topperc)

Changes

To fold a FrameIndex, we need to teach eliminateFrameIndex to respect the uimm9 range.


Full diff: https://github.com/llvm/llvm-project/pull/148779.diff

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp (+4-4)
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 666c76b21e631..880e6b0d48892 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -2936,8 +2936,8 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base,
 /// Similar to SelectAddrRegImm, except that the offset is restricted to uimm9.
 bool RISCVDAGToDAGISel::SelectAddrRegImm9(SDValue Addr, SDValue &Base,
                                           SDValue &Offset) {
-  if (SelectAddrFrameIndex(Addr, Base, Offset))
-    return true;
+  // FIXME: Support FrameIndex. Need to teach eliminateFrameIndex that only
+  // a 9-bit immediate can be folded.
 
   SDLoc DL(Addr);
   MVT VT = Addr.getSimpleValueType();
@@ -2947,8 +2947,8 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm9(SDValue Addr, SDValue &Base,
     if (isUInt<9>(CVal)) {
       Base = Addr.getOperand(0);
 
-      if (auto *FIN = dyn_cast<FrameIndexSDNode>(Base))
-        Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), VT);
+      // FIXME: Support FrameIndex. Need to teach eliminateFrameIndex that only
+      // a 9-bit immediate can be folded.
       Offset = CurDAG->getSignedTargetConstant(CVal, DL, VT);
       return true;
     }

@ukalappa-mips
Copy link
Contributor

To fold a FrameIndex, we need to teach eliminateFrameIndex to respect the uimm9 range.
@topperc ,will look into it and raise a new PR to handle uimm9 range

@topperc topperc merged commit 63d099a into llvm:main Jul 15, 2025
11 checks passed
@topperc topperc deleted the pr/SelectAddrRegImm9 branch July 15, 2025 17:49
@topperc topperc added this to the LLVM 21.x Release milestone Jul 15, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 15, 2025
@topperc
Copy link
Collaborator Author

topperc commented Jul 15, 2025

/cherry-pick 63d099a

@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

/pull-request #148913

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Jul 15, 2025
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 17, 2025
…ddrRegImm9. (llvm#148779)

To fold a FrameIndex, we need to teach eliminateFrameIndex to respect
the uimm9 range.

(cherry picked from commit 63d099a)
djtodoro pushed a commit that referenced this pull request Jul 30, 2025
Reverted the #148779 changes
and

- handled the uimm9 offset in eliminateFrameIndex ()
- updated the testcase.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 30, 2025
… (#149303)

Reverted the llvm/llvm-project#148779 changes
and

- handled the uimm9 offset in eliminateFrameIndex ()
- updated the testcase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants