[llvm] [SDAG] Preserve InBounds in DAGCombines (PR #165424)
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 28 09:25:09 PDT 2025
================
@@ -2715,6 +2715,12 @@ SDValue DAGCombiner::visitPTRADD(SDNode *N) {
(N->getFlags() & N0->getFlags()) & SDNodeFlags::NoUnsignedWrap;
SDValue Add = DAG.getNode(ISD::ADD, DL, IntVT, {Y, Z}, Flags);
AddToWorklist(Add.getNode());
+ // We can't set InBounds even if both original ptradds were InBounds and
+ // NUW: SDAG usually represents pointers as integers, therefore, the
+ // matched pattern behaves as if it had implicit casts:
+ // (ptradd inbounds (inttoptr (ptrtoint (ptradd inbounds x, y))), z)
+ // The outer inbounds ptradd might therefore rely on a provenance that x
+ // does not have.
----------------
arichardson wrote:
Now that we have the c64/c128 value type upstream this could be changed to check PtrVT.isInteger()/PtrVT.isCheriCapability(), but I am also fine with deferring this until the real codegen support has landed upstream.
CC: @jrtc27 @resistor
https://github.com/llvm/llvm-project/pull/165424
More information about the llvm-commits
mailing list