[llvm] cc6d302 - [X86] Fix a bug in TEST with immediate creation

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 23 09:04:01 PDT 2021


Author: Craig Topper
Date: 2021-07-23T09:03:53-07:00
New Revision: cc6d302c91baad2ecf3c9a75ce68d552df0a42b7

URL: https://github.com/llvm/llvm-project/commit/cc6d302c91baad2ecf3c9a75ce68d552df0a42b7
DIFF: https://github.com/llvm/llvm-project/commit/cc6d302c91baad2ecf3c9a75ce68d552df0a42b7.diff

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

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.

Differential Revision: https://reviews.llvm.org/D106634

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index c263c62e2e2e..e9c7ba44b524 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -5446,6 +5446,9 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
       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

diff  --git a/llvm/test/CodeGen/X86/pr51175.ll b/llvm/test/CodeGen/X86/pr51175.ll
index 9800165cc9e7..26d7492d9071 100644
--- a/llvm/test/CodeGen/X86/pr51175.ll
+++ b/llvm/test/CodeGen/X86/pr51175.ll
@@ -15,7 +15,7 @@ define i32 @foo(i16 signext %0, i32 %1, i32* nocapture %2) {
 ; 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


        


More information about the llvm-commits mailing list