[PATCH] [BasicAA] Fix zext & sext handling

Sanjoy Das sanjoy at playingwithpointers.com
Sun Apr 5 19:15:10 PDT 2015


Some drop-by-comments inline in case you find them useful.  I see this patch has been LGTM'ed so feel free to ignore. :)


================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:297
@@ +296,3 @@
+
+    // This check encodes the rule sext(zext(%x, a), b) == zext(%x, a + b)
+    if (isa<SExtInst>(V) && ZExtBits == 0) {
----------------
I'm not sure I understand the comment -- this clause looks like it is implementing `sext(sext(X,a),b)` == `sext(X, a + b)`.

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:302
@@ +301,3 @@
+        // into sext(%x) + sext(c). We'll sext the Offset ourselves:
+        unsigned OldWidth = Offset.getBitWidth();
+        Offset = Offset.trunc(SmallWidth).sext(NewWidth).zextOrSelf(OldWidth);
----------------
Why is the `.zextOrSelf(OldWidth)` or the `.trunc(SmallWidth)` needed?  Isn't `OldWidth` always equal to `SmallWidth`?

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1004
@@ +1003,3 @@
+  // minumum difference between the two. The minimum distance may occur due to
+  // wrapping; consider "add i8 %i, 5": if %i == 7 then 7 + 5 mod 8 == 4, and so
+  // the minimum distance between %i and %i + 5 is 3.
----------------
Do you mean `i3`?  Additions in `i8` are modulo `256`.

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1008
@@ +1007,3 @@
+        Wrapped = APInt::getMaxValue(Width) - MinDiff + APInt(Width, 1);
+  if (Wrapped.ule(MinDiff))
+    MinDiff = Wrapped;
----------------
Minor: `APIntOps::umin` may be clearer here.

http://reviews.llvm.org/D6682

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list