[llvm] [SelectionDAG] Introduce ISD::PTRADD (PR #140017)

Fabian Ritter via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 23:51:04 PDT 2025


ritter-x2a wrote:

> > Should we add these verification asserts(or some equivalent) to `getNode` like we have for `ISD::ADD`
> > ```
> >     assert(VT.isInteger() && "This operator does not apply to FP types!");       
> >     assert(N1.getValueType() == N2.getValueType() &&                             
> >            N1.getValueType() == VT && "Binary operator types must match!");
> > ```
> 
> I agree having these assertions would be useful, and we can relax them once PTRADD starts using actual pointer types instead of integer ones.

This raises the interesting question if we want to restrict the operand types to be the same for now, as it's done for ISD::ADD, or if we just want to require two possibly distinct integer types.
I don't think PTRADDs with different operand types would currently be constructed, since they are only constructed in places where we would also generate ISD::ADD nodes; requiring them to be the same would certainly make some advanced optimizations easier.

If PTRADD nodes with integer operands with different bitwidths should implement the GEP semantics for index types that are wider/narrower than the pointer type (i.e., the bits of the base pointer outside of the width of the index type are not affected by overflows in the index addition), this would add quite a footgun for adding future transformations of PTRADD nodes.

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


More information about the llvm-commits mailing list