[PATCH] D109746: [AA] Teach BasicAA to recognize basic GEP range information.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 15 14:47:46 PDT 2021


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/BasicAliasAnalysis.cpp:1234
+          APInt MinV = R.getLower();
+          APInt MaxV = R.getUpper() - 1;
+          // If Scale < 0, inverse the range so that Scale >= 0.
----------------
Ranges can be wrapping, you're probably looking for getSignedMin() and getSignedMax() here.


================
Comment at: llvm/lib/Analysis/BasicAliasAnalysis.cpp:1243
+          MaxVarIndex =
+              Var.Scale.abs() * MaxV.sextOrTrunc(Var.Scale.getBitWidth());
+        }
----------------
Can't you use the ConstantRange API to perform the multiplication by the scale?

Also, we need to consider overflow here. If the NSW flag is set we can exclude overflow and perform a saturating multiplication, but otherwise we need to take it into account, and this is not just a matter of multiplying the bounds. ConstantRange should do that correctly, though conservatively. We should have tests for this as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109746/new/

https://reviews.llvm.org/D109746



More information about the llvm-commits mailing list