[PATCH] D71568: [InstCombine] `select + mul` -> `select + shl` with power of twos.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 14:49:20 PST 2019


lebedev.ri added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:267-269
+  Constant *C1 = getLogBase2(Op0->getType(), cast<Constant>(Op1));
+  if (!C1)
+    llvm_unreachable("Failed to constant fold mul -> logbase2");
----------------
What happens with undef lanes?
(they should become `0`, do not keep them as `undef`.
there was some helper for that, can't find it now "replace undef values with")


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:274-275
+  if (I.hasNoSignedWrap()) {
+    const APInt *V;
+    if (match(C1, m_APInt(V)) && *V != V->getBitWidth() - 1)
+      Shl->setHasNoSignedWrap();
----------------
This isn't sound.
We want to not propagate `NSW` if *any* lane matches this predicate, not just if they all do..
So you want
```
if (I.hasNoSignedWrap() && !C1.isNotMinSignedValue())
  Shl->setHasNoSignedWrap();
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71568





More information about the llvm-commits mailing list