[llvm] Preserve range metadata when load is narrowed (PR #128144)

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 21 15:35:34 PST 2025


================
@@ -14903,12 +14903,39 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
   AddToWorklist(NewPtr.getNode());
 
   SDValue Load;
-  if (ExtType == ISD::NON_EXTLOAD)
-    Load = DAG.getLoad(VT, DL, LN0->getChain(), NewPtr,
-                       LN0->getPointerInfo().getWithOffset(PtrOff),
-                       LN0->getOriginalAlign(),
-                       LN0->getMemOperand()->getFlags(), LN0->getAAInfo());
-  else
+  if (ExtType == ISD::NON_EXTLOAD) {
+    const MDNode *OldRanges = LN0->getRanges();
+    const MDNode *NewRanges = nullptr;
+    /* If LSBs are loaded and all bounds in the OldRanges metadata fit in
+       the narrower size, preserve the range information by translating
----------------
LU-JOHN wrote:

Added negative test where bounds cannot fit in 32-bits.

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


More information about the llvm-commits mailing list