[PATCH] D126213: [DAGCombiner][AArch64] Don't fold (smulo x, 2) -> (saddo x, x) if VT is i2.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 08:41:22 PDT 2022


craig.topper created this revision.
craig.topper added reviewers: RKSimon, efriedma, spatel.
Herald added subscribers: StephenFan, ecnelises, hiraditya, kristof.beyls.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.

If the VT is i2, then 2 is really -2.

Test has not been commited yet, but diff shows the change.

Fixes PR55644.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126213

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AArch64/pr55644.ll


Index: llvm/test/CodeGen/AArch64/pr55644.ll
===================================================================
--- llvm/test/CodeGen/AArch64/pr55644.ll
+++ llvm/test/CodeGen/AArch64/pr55644.ll
@@ -5,9 +5,10 @@
 ; CHECK-LABEL: f:
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    sbfx w8, w0, #0, #2
-; CHECK-NEXT:    add w8, w8, w8
-; CHECK-NEXT:    lsl w9, w8, #30
-; CHECK-NEXT:    cmp w8, w9, asr #30
+; CHECK-NEXT:    lsl w8, w8, #1
+; CHECK-NEXT:    neg w9, w8
+; CHECK-NEXT:    lsl w9, w9, #30
+; CHECK-NEXT:    cmn w8, w9, asr #30
 ; CHECK-NEXT:    cset w0, ne
 ; CHECK-NEXT:    ret
   %2 = call { i2, i1 } @llvm.smul.with.overflow.i2(i2 %0, i2 -2)
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4913,7 +4913,9 @@
                      DAG.getConstant(0, DL, CarryVT));
 
   // (mulo x, 2) -> (addo x, x)
-  if (N1C && N1C->getAPIntValue() == 2)
+  // FIXME: This needs a freeze.
+  if (N1C && N1C->getAPIntValue() == 2 &&
+      (!IsSigned || VT.getScalarSizeInBits() > 2))
     return DAG.getNode(IsSigned ? ISD::SADDO : ISD::UADDO, DL,
                        N->getVTList(), N0, N0);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126213.431388.patch
Type: text/x-patch
Size: 1269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220523/128c0964/attachment.bin>


More information about the llvm-commits mailing list