[llvm] [CodeGenPrepare] Transform `shl X, cttz(Y)` to `mul (Y & -Y), X` if cttz is unsupported (PR #85066)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 21:01:32 PDT 2024


================
@@ -8396,7 +8396,29 @@ bool CodeGenPrepare::optimizeInst(Instruction *I, ModifyDT &ModifiedDT) {
     return true;
 
   switch (I->getOpcode()) {
-  case Instruction::Shl:
+  case Instruction::Shl: {
+    // shl X, cttz(Y) -> mul (Y & -Y), X if cttz is unsupported on the target.
+    Value *Y;
+    if (match(I->getOperand(1),
+              m_OneUse(m_Intrinsic<Intrinsic::cttz>(m_Value(Y))))) {
----------------
topperc wrote:

You can match an intrinsic without specifying a match for all operands? That's surprising.

https://github.com/llvm/llvm-project/pull/85066


More information about the llvm-commits mailing list