[PATCH] [SLSR] consider &B[S << i] as &B[(1 << i) * S]

Sanjoy Das sanjoy at playingwithpointers.com
Sun Apr 5 23:37:20 PDT 2015


Super-pedantic nit on the comment message: I think it should be "This reduces handling &B[(i << 1) * s] to handling &B[i * S]."


================
Comment at: lib/Transforms/Scalar/StraightLineStrengthReduce.cpp:372
@@ +371,3 @@
+  } else if (match(ArrayIdx, m_NSWShl(m_Value(LHS), m_ConstantInt(RHS)))) {
+    // GEP = Base + sext(LHS <<nsw RHS) * ElementSize
+    //     = Base + sext(LHS *nsw (1 << RHS)) * ElementSize
----------------
`A << B` is `nsw` does not imply `A * (1 << B)` is `nsw`.  For `i8` a counterexample is `A` = `-1` and `B` = `7` -- `-1 << 7` does not sign-overflow but `-1 * -128` sign-overflows.  In general, for `iN` I think the only counterexample has `B` = `N-1`; if that can be proved (I haven't tried) then it should be sufficient to guard for just that.

http://reviews.llvm.org/D8837

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






More information about the llvm-commits mailing list