[PATCH] D106634: [X86] Fix a bug in TEST with immediate creation

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 22 23:28:35 PDT 2021


craig.topper created this revision.
craig.topper added reviewers: pengfei, spatel, RKSimon.
Herald added a subscriber: hiraditya.
craig.topper requested review of this revision.
Herald added a project: LLVM.

This code tries to form a TEST from CMP+AND with an optional
truncate in between. If we looked through the truncate, we may
have extra bits in the AND mask that shouldn't participate in
the checks. Normally SimplifyDemendedBits takes care of this, but
the AND may have another user. So manually mask out any extra bits.

Fixes PR51175.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106634

Files:
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/test/CodeGen/X86/pr51175.ll


Index: llvm/test/CodeGen/X86/pr51175.ll
===================================================================
--- llvm/test/CodeGen/X86/pr51175.ll
+++ llvm/test/CodeGen/X86/pr51175.ll
@@ -15,7 +15,7 @@
 ; CHECK-NEXT:    andl $65527, %eax # imm = 0xFFF7
 ; CHECK-NEXT:    movl %eax, (%rdx)
 ; CHECK-NEXT:    xorl %eax, %eax
-; CHECK-NEXT:    testl $-9, %edi
+; CHECK-NEXT:    testb $-9, %dil
 ; CHECK-NEXT:    cmovel %esi, %eax
 ; CHECK-NEXT:    retq
   %4 = add i16 %0, 1
Index: llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -5446,6 +5446,9 @@
       ConstantSDNode *C = dyn_cast<ConstantSDNode>(N0.getOperand(1));
       if (!C) break;
       uint64_t Mask = C->getZExtValue();
+      // We may have looked through a truncate so mask off any bits that
+      // shouldn't be part of the compare.
+      Mask &= maskTrailingOnes<uint64_t>(CmpVT.getScalarSizeInBits());
 
       // Check if we can replace AND+IMM64 with a shift. This is possible for
       // masks/ like 0xFF000000 or 0x00FFFFFF and if we care only about the zero


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106634.361097.patch
Type: text/x-patch
Size: 1183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210723/b3e86419/attachment.bin>


More information about the llvm-commits mailing list