[llvm] [LAA] getPointersDiff(): Add ExpensivePtrCheck argument (PR #226333)

Vasileios Porpodas via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 13:05:48 PDT 2026


vporpo wrote:

> What's the motivating case? 

Complicated pointer expressions like this one:
```
define void @ptr_diff(ptr %ptr, i64 %val) {
  %or = or i64 %val, %val
  %rem4 = shl i64 %val, 7
  %mul5 = and i64 %rem4, 896
  %mul6 = shl nuw nsw i64 %val, 3
  %add1 = add nuw i64 %mul5, %mul6
  %shl = shl i64 %add1, 10

  %idx0 = add i64 %shl, %or
  %idx1 = or disjoint i64 %idx0, 1

  %gep0 = getelementptr float, ptr %ptr, i64 %idx0
  %gep1 = getelementptr float, ptr %ptr, i64 %idx1
  ret void
```

> We may wish to improve computeConstantDifference() instead.

I haven't looked into the internals of `computeConstantDifference()` but the comment in the header file says the following, so it looks to me like it is not always precise by design.
```
  /// This is intended to be a cheaper version of getMinusSCEV.  We can be
  /// frugal here since we just bail out of actually constructing and
  /// canonicalizing an expression in the cases where the result isn't going
  /// to be a constant.
```


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


More information about the llvm-commits mailing list