[llvm] [SelectionDAG][AMDGPU] Preserve known bits for demoted sret pointers (PR #203468)

Keshav Vinayak Jha via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 00:46:21 PDT 2026


================
@@ -3983,8 +3983,36 @@ void TargetLowering::computeKnownFPClassForTargetInstr(
 
 void TargetLowering::computeKnownBitsForFrameIndex(
   const int FrameIdx, KnownBits &Known, const MachineFunction &MF) const {
+  computeKnownBitsForStackObjectPointer(
+      Known, MF, MF.getFrameInfo().getObjectAlign(FrameIdx));
+}
+
+void TargetLowering::computeKnownBitsForStackObjectPointer(
+    KnownBits &Known, const MachineFunction &, Align Alignment) const {
   // The low bits are known zero if the pointer is aligned.
-  Known.Zero.setLowBits(Log2(MF.getFrameInfo().getObjectAlign(FrameIdx)));
+  Known.Zero.setLowBits(Log2(Alignment));
+}
+
+SDValue TargetLowering::annotateStackObjectPointer(SDValue Ptr,
+                                                   SelectionDAG &DAG,
+                                                   const SDLoc &DL,
+                                                   Align Alignment) const {
+  EVT PtrVT = Ptr.getValueType();
+
+  unsigned RegSize = PtrVT.getScalarSizeInBits();
+  KnownBits Known(RegSize);
+  computeKnownBitsForStackObjectPointer(Known, DAG.getMachineFunction(),
+                                        Alignment);
+
+  unsigned NumZeroBits = Known.countMinLeadingZeros();
+  if (!NumZeroBits)
+    return Ptr;
+
+  // TODO: This helper only materializes leading-zero facts. Use
----------------
keshavvinayak01 wrote:

Makes sense. The functions are well documented, and it can be changed later if required, TODO makes it seem incomplete.

https://github.com/llvm/llvm-project/pull/203468


More information about the llvm-commits mailing list