[PATCH] D108408: [InstCombine] Transform X == 0 ? 0 : X * Y --> X * freeze(Y).

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 11 12:21:27 PDT 2021


nikic accepted this revision.
nikic added a comment.

LG



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:768
+
+  auto *FalseValI = cast<Instruction>(FalseVal);
+  auto *FrY = new FreezeInst(Y, Y->getName() + ".fr", FalseValI);
----------------
fzhinkin wrote:
> nikic wrote:
> > I believe this may fail if the multiplication is a constant expression (we should bail in that case).
> I was not able to reproduce that case w/ tests because all my const expressions were folded before invocation of newly added folding, but I'll add the check, thanks.
The trick to that is usually embedding globals in to the constant expression, something like `mul (i64 ptrtoint (i8* @g1 to i64). i64 ptrtoint (i8* @g2 to i64))` might do.


================
Comment at: llvm/test/Transforms/InstCombine/select.ll:2888
 ; CHECK-LABEL: @mul_select_ne_zero(
-; CHECK-NEXT:    [[C_NOT:%.*]] = icmp eq i32 [[X:%.*]], 0
-; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X]], [[Y:%.*]]
----------------
As you can see, this doesn't actually check the `ne` case, as the icmp is canonicalize to eq first. I think it may be possible to prevent this by adding an extra use of the icmp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108408



More information about the llvm-commits mailing list