Skip to content

Commit 74784a5

Browse files
committed
[X86] In shrinkAndImmediate, place the new constant into the topological sort.
Revert the change to use APInt::isSignedIntN from 5ff5cf8. Its clear that the games we were playing to avoid the topological sort aren't working. So just fix it once and for all. Fixes PR48888.
1 parent 63273fc commit 74784a5

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const {
617617
// best of both worlds.
618618
if (U->getOpcode() == ISD::AND &&
619619
Imm->getAPIntValue().getBitWidth() == 64 &&
620-
Imm->getAPIntValue().isSignedIntN(32))
620+
Imm->getAPIntValue().isIntN(32))
621621
return false;
622622

623623
// If this really a zext_inreg that can be represented with a movzx
@@ -4282,6 +4282,7 @@ bool X86DAGToDAGISel::shrinkAndImmediate(SDNode *And) {
42824282

42834283
// A negative mask allows a smaller encoding. Create a new 'and' node.
42844284
SDValue NewMask = CurDAG->getConstant(NegMaskVal, SDLoc(And), VT);
4285+
insertDAGNode(*CurDAG, SDValue(And, 0), NewMask);
42854286
SDValue NewAnd = CurDAG->getNode(ISD::AND, SDLoc(And), VT, And0, NewMask);
42864287
ReplaceNode(And, NewAnd.getNode());
42874288
SelectCode(NewAnd.getNode());

llvm/test/CodeGen/X86/pr48458.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
define i1 @foo(i64* %0) {
55
; CHECK-LABEL: foo:
66
; CHECK: # %bb.0: # %top
7-
; CHECK-NEXT: movq (%rdi), %rax
8-
; CHECK-NEXT: andq $-2147483648, %rax # imm = 0x80000000
7+
; CHECK-NEXT: movq $-2147483648, %rax # imm = 0x80000000
8+
; CHECK-NEXT: testq %rax, (%rdi)
99
; CHECK-NEXT: sete %al
1010
; CHECK-NEXT: retq
1111
top:

llvm/test/CodeGen/X86/pr48888.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
3+
4+
define void @test(i64* %p) nounwind {
5+
; CHECK-LABEL: test:
6+
; CHECK: # %bb.0: # %bb
7+
; CHECK-NEXT: movq (%rdi), %rax
8+
; CHECK-NEXT: andl $-2, %eax
9+
; CHECK-NEXT: cmpq $2, %rax
10+
; CHECK-NEXT: cmpl $2, %eax
11+
; CHECK-NEXT: retq
12+
bb:
13+
%i = load i64, i64* %p, align 8, !range !0
14+
%i1 = and i64 %i, 6
15+
%i2 = icmp eq i64 %i1, 2
16+
br i1 %i2, label %bb3, label %bb5
17+
18+
bb3: ; preds = %bb
19+
%i4 = icmp ne {}* undef, null
20+
br label %bb5
21+
22+
bb5: ; preds = %bb3, %bb
23+
br label %bb6
24+
25+
bb6: ; preds = %bb5
26+
br i1 %i2, label %bb7, label %bb9
27+
28+
bb7: ; preds = %bb6
29+
%i8 = getelementptr inbounds i64, i64* undef, i64 5
30+
br label %bb9
31+
32+
bb9: ; preds = %bb7, %bb6
33+
ret void
34+
}
35+
36+
!0 = !{i64 0, i64 5}

0 commit comments

Comments
 (0)