[llvm] [SDAG] Preserve InBounds in DAGCombines (PR #165424)
Fabian Ritter via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 29 00:40:05 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.
----------------
ritter-x2a wrote:
I'd leave that to a CHERI-upstreaming-related patch that should (among other things) remove this assert in the lines above this change to enable PTRADD combines for CHERI:
```
assert(PtrVT == IntVT &&
"PTRADD with different operand types is not supported");
```
https://github.com/llvm/llvm-project/pull/165424
More information about the llvm-commits
mailing list