ritter-x2a wrote:

> This seems semantically ambiguous.
> 
> In GlobalISel, you have G_PTR_ADD, and inbounds on that has an obvious 
> meaning; G_PTR_ADD has basically the same semantics as getelementptr. But in 
> SelectionDAG, we don't have that; we just have a plain ISD::ADD. How do you 
> tell which operand is the pointer? The obvious heuristic is outright wrong: 
> you can't assume a value is being used as a pointer just because its value is 
> equal to the address of some variable.

I see your point. We could define the semantics of an inbounds ISD::ADD to be 
"The result is an address into an allocated object and (exactly) one of the 
operands is an address into the same allocated object."
I think this might be strong enough for the concrete goal that I have in mind 
(PR #131863), but I agree that it would be better to have a flag that is easier 
to make use of.

What do you think about a "ConstInBoundsOffset" flag instead (suggestions for 
better names would be much appreciated), meaning "One operand is a constant 
offset and the other is an address pointing into the same allocated object as 
the result"?
While a lot narrower in scope, it would be easier to make use of that.

https://github.com/llvm/llvm-project/pull/131862
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to