[PATCH] [BasicAA] Fix zext & sext handling

Sanjoy Das sanjoy at playingwithpointers.com
Wed May 6 19:15:46 PDT 2015


================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:275
@@ +274,3 @@
+      if (isa<OverflowingBinaryOperator>(BOp)) {
+        NUW &= BOp->hasNoUnsignedWrap();
+        NSW &= BOp->hasNoSignedWrap();
----------------
Note that currently in the LangRef, `shl nsw X, Y` is not the same as `mul nsw X (1 << Y)`, the LangRef has a bug in this regard.  David has an out of tree patch to fix this http://reviews.llvm.org/D8890 but meanwhile you might want to not propagate `nuw` and `nsw` for shifts.

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:300
@@ +299,3 @@
+    // we'll only execute the if-true block if we sext'ing a value that hasn't
+    // been zext'ed (i.e. we'll actually sign extend the variable, instead of
+    // converting the sext to a zext).
----------------
Very minor, but I think it will be clearer if you just add an annotation to each branch of the if statement:

```
if (is<SEXtInst>(V) && ZExtBits == 0) {
  // sext(sext(A)) == sext(A)
```

etc. instead of a comprehensive meta comment.

http://reviews.llvm.org/D6682

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






More information about the llvm-commits mailing list