Skip to content

Commit 961c66c

Browse files
committed
[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
1 parent dab4121 commit 961c66c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4828,7 +4828,9 @@ bool X86DAGToDAGISel::shrinkAndImmediate(SDNode *And) {
48284828

48294829
// The variable operand must be all zeros in the top bits to allow using the
48304830
// new, negative constant as the mask.
4831-
if (!CurDAG->MaskedValueIsZero(And0, HighZeros))
4831+
// TODO: Handle constant folding?
4832+
KnownBits Known0 = CurDAG->computeKnownBits(And0);
4833+
if (Known0.isConstant() || !HighZeros.isSubsetOf(Known0.Zero))
48324834
return false;
48334835

48344836
// Check if the mask is -1. In that case, this is an unnecessary instruction

llvm/test/CodeGen/X86/pr114360.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define i64 @test() {
66
; CHECK-LABEL: test:
77
; CHECK: # %bb.0:
88
; CHECK-NEXT: movabsq $-4294967295, %rax # imm = 0xFFFFFFFF00000001
9+
; CHECK-NEXT: movzwl %ax, %eax
910
; CHECK-NEXT: retq
1011
%x = bitcast i64 u0xffffffff00000001 to i64
1112
%t = trunc i64 %x to i32

0 commit comments

Comments
 (0)