llvm.org GIT mirror llvm / e9ec240
[DAG] Avoid deleting nodes before combining them. When replacing a node and it's operand, replacing the operand node may cause the deletion of the original node leading to an assertion failure. Case around these replacements to avoid this without relying on inspecting the DELETED_NODE opcode in various extend dagcombiner cases. Fixes PR32515. Reviewers: dbabokin, RKSimon, davide, chandlerc Subscribers: chandlerc, llvm-commits Differential Revision: https://reviews.llvm.org/D34095 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308330 91177308-0d34-0410-b5e6-96231b3b80d8 Nirav Dave 3 years ago
3 changed file(s) with 58 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
71707170 SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
71717171 N0.getValueType(), ExtLoad);
71727172 ExtendSetCCUses(SetCCs, Trunc, ExtLoad, DL, ISD::SIGN_EXTEND);
7173 CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
7173 // If the load value is used only by N, replace it via CombineTo N.
7174 if (N0.getValue(0).hasOneUse())
7175 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7176 else
7177 CombineTo(LN0, Trunc, ExtLoad.getValue(1));
71747178 return CombineTo(N, ExtLoad); // Return N so it doesn't get rechecked!
71757179 }
71767180 }
72287232 SDLoc(N0.getOperand(0)),
72297233 N0.getOperand(0).getValueType(), ExtLoad);
72307234 ExtendSetCCUses(SetCCs, Trunc, ExtLoad, DL, ISD::SIGN_EXTEND);
7231 CombineTo(N0.getOperand(0).getNode(), Trunc, ExtLoad.getValue(1));
7235 // If the load value is used only by N, replace it via CombineTo N.
7236 if (SDValue(LN0, 0).hasOneUse())
7237 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7238 else
7239 CombineTo(LN0, Trunc, ExtLoad.getValue(1));
72327240 return CombineTo(N, And); // Return N so it doesn't get rechecked!
72337241 }
72347242 }
74697477 SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
74707478 N0.getValueType(), ExtLoad);
74717479 ExtendSetCCUses(SetCCs, Trunc, ExtLoad, SDLoc(N), ISD::ZERO_EXTEND);
7472 CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
7480 // If the load value is used only by N, replace it via CombineTo N.
7481 if (SDValue(LN0, 0).hasOneUse())
7482 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7483 else
7484 CombineTo(LN0, Trunc, ExtLoad.getValue(1));
74737485 return CombineTo(N, ExtLoad); // Return N so it doesn't get rechecked!
74747486 }
74757487 }
75217533 SDLoc(N0.getOperand(0)),
75227534 N0.getOperand(0).getValueType(), ExtLoad);
75237535 ExtendSetCCUses(SetCCs, Trunc, ExtLoad, DL, ISD::ZERO_EXTEND);
7524 CombineTo(N0.getOperand(0).getNode(), Trunc, ExtLoad.getValue(1));
7536 // If the load value is used only by N, replace it via CombineTo N.
7537 if (SDValue(LN0, 0).hasOneUse())
7538 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7539 else
7540 CombineTo(LN0, Trunc, ExtLoad.getValue(1));
75257541 return CombineTo(N, And); // Return N so it doesn't get rechecked!
75267542 }
75277543 }
76947710 LN0->getChain(),
76957711 LN0->getBasePtr(), N0.getValueType(),
76967712 LN0->getMemOperand());
7697 CombineTo(N, ExtLoad);
76987713 SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
76997714 N0.getValueType(), ExtLoad);
7700 CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
77017715 ExtendSetCCUses(SetCCs, Trunc, ExtLoad, SDLoc(N),
77027716 ISD::ANY_EXTEND);
7703 return SDValue(N, 0); // Return N so it doesn't get rechecked!
7717 // If the load value is used only by N, replace it via CombineTo N.
7718 if (N0.hasOneUse())
7719 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7720 else
7721 CombineTo(LN0, Trunc, ExtLoad.getValue(1));
7722 return CombineTo(N, ExtLoad); // Return N so it doesn't get rechecked!
77047723 }
77057724 }
77067725
16291629 ; CHECK-LABEL: f1:
16301630 ; CHECK: ## BB#0: ## %entry
16311631 ; CHECK-NEXT: movzbl {{.*}}(%rip), %edi
1632 ; CHECK-NEXT: movl %edi, %eax
1633 ; CHECK-NEXT: xorb $1, %al
1632 ; CHECK-NEXT: movb {{.*}}(%rip), %al
1633 ; CHECK-NEXT: notb %al
1634 ; CHECK-NEXT: andb $1, %al
16341635 ; CHECK-NEXT: movb %al, {{.*}}(%rip)
16351636 ; CHECK-NEXT: xorl $1, %edi
16361637 ; CHECK-NEXT: jmp _f2 ## TAILCALL
0 ; RUN: llc -O0 -mtriple=x86_64-unknown -mcpu=skx -o - %s
1 ; RUN: llc -mtriple=x86_64-unknown -mcpu=skx -o - %s
2 ; RUN: llc -O0 -mtriple=i686-unknown -mcpu=skx -o - %s
3 ; RUN: llc -mtriple=i686-unknown -mcpu=skx -o - %s
4 ; REQUIRES: asserts
5
6 @var_26 = external global i16, align 2
7
8 define void @foo() #0 {
9 %1 = alloca i16, align 2
10 %2 = load i16, i16* @var_26, align 2
11 %3 = zext i16 %2 to i32
12 %4 = icmp ne i32 %3, 7
13 %5 = zext i1 %4 to i16
14 store i16 %5, i16* %1, align 2
15 %6 = load i16, i16* @var_26, align 2
16 %7 = zext i16 %6 to i32
17 %8 = and i32 1, %7
18 %9 = shl i32 %8, 0
19 %10 = load i16, i16* @var_26, align 2
20 %11 = zext i16 %10 to i32
21 %12 = icmp ne i32 %11, 7
22 %13 = zext i1 %12 to i32
23 %14 = and i32 %9, %13
24 %15 = icmp ne i32 %14, 0
25 %16 = zext i1 %15 to i8
26 store i8 %16, i8* undef, align 1
27 unreachable
28 }