[PATCH] D63652: [InstCombine] (1 << (C - x)) -> ((1 << C) >> x) if C is bitwidth - 1

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 08:38:16 PDT 2019


nikic added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:677
+  // (1 << (C - x)) -> ((1 << C) >> x) if C is bitwidth - 1
+  if (match(Op0, m_APInt(ShlOp0)) && ShlOp0->getSExtValue() == 1 &&
+      match(Op1, m_Sub(m_APInt(C), m_Value(X))) &&
----------------
getSExtValue will assert if the value is too large. You can use `ShlOp0->isOneValue()` here.


================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:679
+      match(Op1, m_Sub(m_APInt(C), m_Value(X))) &&
+      C->getZExtValue() == BitWidth - 1)
+    return BinaryOperator::CreateLShr(ConstantInt::get(Ty, ShlOp0->shl(*C)), X);
----------------
Same issue here. I think just doing `*C == BitWidth - 1` should work.


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

https://reviews.llvm.org/D63652





More information about the llvm-commits mailing list