Skip to content

Commit 917b3d1

Browse files
[SDAG] Intersect poison-generating flags after CSE (#114650)
This patch intersects poison-generating flags after CSE to fix assertion failure reported in #112354 (comment). Co-authored-by: Antonio Frighetto <[email protected]>
1 parent 67c8b0e commit 917b3d1

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10318,8 +10318,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1031810318
AddNodeIDNode(ID, Opcode, VTs, Ops);
1031910319
void *IP = nullptr;
1032010320

10321-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP))
10321+
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
10322+
E->intersectFlagsWith(Flags);
1032210323
return SDValue(E, 0);
10324+
}
1032310325

1032410326
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
1032510327
createOperands(N, Ops);
@@ -10524,8 +10526,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1052410526
FoldingSetNodeID ID;
1052510527
AddNodeIDNode(ID, Opcode, VTList, Ops);
1052610528
void *IP = nullptr;
10527-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP))
10529+
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
10530+
E->intersectFlagsWith(Flags);
1052810531
return SDValue(E, 0);
10532+
}
1052910533

1053010534
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTList);
1053110535
createOperands(N, Ops);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=arm-eabi -o - %s | FileCheck %s
3+
4+
; Ensure poison-generating flags are stripped by the time a freeze operand is visited.
5+
6+
define i1 @drop_flags(i32 noundef %numentries, i64 %cond, i64 %arg) {
7+
; CHECK-LABEL: drop_flags:
8+
; CHECK: @ %bb.0: @ %entry
9+
; CHECK-NEXT: ldm sp, {r1, r12}
10+
; CHECK-NEXT: subs r1, r2, r1
11+
; CHECK-NEXT: sbcs r1, r3, r12
12+
; CHECK-NEXT: movlo r0, r2
13+
; CHECK-NEXT: rsbs r1, r0, #0
14+
; CHECK-NEXT: adc r0, r0, r1
15+
; CHECK-NEXT: mov pc, lr
16+
entry:
17+
%cmp4 = icmp samesign ult i64 %cond, %arg
18+
%conv6 = trunc nuw i64 %cond to i32
19+
%spec.select = select i1 %cmp4, i32 %conv6, i32 %numentries
20+
%spec.select.fr = freeze i32 %spec.select
21+
%cmpz = icmp eq i32 %spec.select.fr, 0
22+
ret i1 %cmpz
23+
}

0 commit comments

Comments
 (0)