[PATCH] D114729: [InstCombine] try to fold 'or' into 'mul' operand

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 29 12:34:08 PST 2021


spatel marked an inline comment as done.
spatel added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2645
+  if (match(&I,
+            m_c_Or(m_OneUse(m_Mul(m_Value(X), m_Value(Y))), m_Deferred(X))) &&
+      haveNoCommonBitsSet(Op0, Op1, DL)) {
----------------
lebedev.ri wrote:
> But if mul is not one-use yet the y is an immediate, don't we still want to fold?
That's not clearly better IMO. It reduces the computation chain, but we'd be replacing an 'or' with a 'mul'. That could regress codegen (especially for targets/types where the mul is not supported), and the backend can't undo that currently.

This case is shown as the 1st negative test in the patch. These are the options:
  %m = mul i32 %x, 24
  call void @use(i32 %m)
  %r = or i32 %m, %x

vs.

  %m = mul i32 %x, 24
  call void @use(i32 %m)
  %r = mul i32 %x, 25



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

https://reviews.llvm.org/D114729



More information about the llvm-commits mailing list