[llvm] 961c66c - [X86] shrinkAndImmediate - bail on failed constant fold

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 28 11:01:11 PST 2024


Author: Simon Pilgrim
Date: 2024-11-28T19:00:43Z
New Revision: 961c66c57144ac46b65277338d9d1ebdc284e0df

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

LOG: [X86] shrinkAndImmediate - bail on failed constant fold

Workaround for issue #114360 where shrinkAndImmediate folds away the AND after the ZEXT has already been folded away to SUBREG_TO_REG losing the implicit zext guarantee.

There's the possibility that other instructions can result in a similar regression, but this is a stopgap until I can investigate whether shrinkAndImmediate needs to be replaced entirely.

Fixes #114360

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index 0641dca07a8903..93d196d0fde5cf 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -4828,7 +4828,9 @@ bool X86DAGToDAGISel::shrinkAndImmediate(SDNode *And) {
 
   // The variable operand must be all zeros in the top bits to allow using the
   // new, negative constant as the mask.
-  if (!CurDAG->MaskedValueIsZero(And0, HighZeros))
+  // TODO: Handle constant folding?
+  KnownBits Known0 = CurDAG->computeKnownBits(And0);
+  if (Known0.isConstant() || !HighZeros.isSubsetOf(Known0.Zero))
     return false;
 
   // Check if the mask is -1. In that case, this is an unnecessary instruction

diff  --git a/llvm/test/CodeGen/X86/pr114360.ll b/llvm/test/CodeGen/X86/pr114360.ll
index 025135e4c59b6f..302eed47e5fa4e 100644
--- a/llvm/test/CodeGen/X86/pr114360.ll
+++ b/llvm/test/CodeGen/X86/pr114360.ll
@@ -6,6 +6,7 @@ define i64 @test() {
 ; CHECK-LABEL: test:
 ; CHECK:       # %bb.0:
 ; CHECK-NEXT:    movabsq $-4294967295, %rax # imm = 0xFFFFFFFF00000001
+; CHECK-NEXT:    movzwl %ax, %eax
 ; CHECK-NEXT:    retq
   %x = bitcast i64 u0xffffffff00000001 to i64
   %t = trunc i64 %x to i32


        


More information about the llvm-commits mailing list