[PATCH] D146787: [X86] Teach computeKnownBitsForTargetNode about MUL_IMM

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 00:11:13 PDT 2023


kazu created this revision.
Herald added subscribers: foad, pengfei, hiraditya.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch teaches computeKnownBitsForTargetNode about MUL_IMM.

MUL_IMM comes up in certain select of constants.  Specifically, it is
used to multiply the result of SETCC.  Computing the known zero bits
of MUL_IMM allows matchAddressRecursively us to convert some OR into
ADD, which eventually becomes a part of LEA.

This patch fixes:

https://github.com/llvm/llvm-project/issues/61365


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146787

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/select-constant-lea.ll


Index: llvm/test/CodeGen/X86/select-constant-lea.ll
===================================================================
--- llvm/test/CodeGen/X86/select-constant-lea.ll
+++ llvm/test/CodeGen/X86/select-constant-lea.ll
@@ -8,8 +8,7 @@
 ; BASE-NEXT:    xorl %eax, %eax
 ; BASE-NEXT:    cmpl $10, %edi
 ; BASE-NEXT:    setae %al
-; BASE-NEXT:    leal (%rax,%rax,4), %eax
-; BASE-NEXT:    orl $8, %eax
+; BASE-NEXT:    leal 8(%rax,%rax,4), %eax
 ; BASE-NEXT:    retq
 ;
 ; SLOWLEA3-LABEL: select_unsigned_lt_10_8_13j:
@@ -18,7 +17,7 @@
 ; SLOWLEA3-NEXT:    cmpl $10, %edi
 ; SLOWLEA3-NEXT:    setae %al
 ; SLOWLEA3-NEXT:    leal (%rax,%rax,4), %eax
-; SLOWLEA3-NEXT:    orl $8, %eax
+; SLOWLEA3-NEXT:    addl $8, %eax
 ; SLOWLEA3-NEXT:    retq
   %2 = icmp ult i32 %0, 10
   %3 = select i1 %2, i32 8, i32 13
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -38098,6 +38098,15 @@
   Known.resetAll();
   switch (Opc) {
   default: break;
+  case X86ISD::MUL_IMM: {
+    KnownBits Known2 =
+        DAG.computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
+    APInt Val = Known2.Zero;
+    Val.flipAllBits();
+    Val *= cast<ConstantSDNode>(Op.getOperand(1))->getAPIntValue();
+    Known.Zero.setBitsFrom(Val.getActiveBits());
+    break;
+  }
   case X86ISD::SETCC:
     Known.Zero.setBitsFrom(1);
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146787.507976.patch
Type: text/x-patch
Size: 1472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230324/3819c2ed/attachment.bin>


More information about the llvm-commits mailing list