[PATCH] [InstCombine] Added transformation from sdiv to ashr

David Majnemer david.majnemer at gmail.com
Fri May 8 22:19:07 PDT 2015


You don't have any testcases.

What stops you from transforming `sdiv i32 %x, 2` into `ashr i32 %x, 1` ?  Such a transform wouldn't be correct because the two are not equivalent when `%x` is `-1`.

The transform on line 1215 already tries to turn signed division into unsigned division when it is safe to do so.  From there, unsigned division will be canonicalized into a shift when we can.


================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:1138-1139
@@ +1137,4 @@
+  const APInt &C = cast<Constant>(Op1)->getUniqueInteger();
+  BinaryOperator *AShr = BinaryOperator::CreateExactAShr(
+                                                         Op0, ConstantInt::get(Op0->getType(), C.logBase2()));
+  return AShr;
----------------
This doesn't look correctly formatted, please use clang-format.

http://reviews.llvm.org/D9607

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






More information about the llvm-commits mailing list