[llvm] [ValueTracking] Allow getUnderlyingPointer to look through inttoptr/ptrtoint round trip casts (PR #146432)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 08:41:15 PDT 2025
================
@@ -1602,6 +1602,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
// Figure out what objects these things are pointing to if we can.
const Value *O1 = getUnderlyingObject(V1, MaxLookupSearchDepth);
const Value *O2 = getUnderlyingObject(V2, MaxLookupSearchDepth);
+ removeRoundTripCasts(O1);
+ removeRoundTripCasts(O2);
----------------
nikic wrote:
It's the same problem as in the general case. You can't look through inttoptr/ptrtoint cast in any code that does provenance-based reasoning, which BasicAA does (e.g. via isIdentifiedObject).
It *is* possible to look through these casts, but you can only reason about the *address* of the pointer after you do. This means that in your example, we would not be able to prove these are NoAlias because the underlying object is different -- but we *could* prove that the accessed address ranges must be disjoint.
It's possible, but this would need substantial changes to BasicAA and the AA API.
https://github.com/llvm/llvm-project/pull/146432
More information about the llvm-commits
mailing list