Skip to content

Commit 3b16d8c

Browse files
authored
[SystemZ] Don't crash on undef source in shouldCoalesce() (#78056)
SystemZRegisterInfo::shouldCoalesce() has to be able to handle an undef source.
1 parent f3d0788 commit 3b16d8c

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

llvm/lib/Target/SystemZ/SystemZRegisterInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ bool SystemZRegisterInfo::shouldCoalesce(MachineInstr *MI,
387387

388388
// Coalesce anything which is not a COPY involving a subreg to/from GR128.
389389
if (!(NewRC->hasSuperClassEq(&SystemZ::GR128BitRegClass) &&
390-
(getRegSizeInBits(*SrcRC) <= 64 || getRegSizeInBits(*DstRC) <= 64)))
390+
(getRegSizeInBits(*SrcRC) <= 64 || getRegSizeInBits(*DstRC) <= 64) &&
391+
!MI->getOperand(1).isUndef()))
391392
return true;
392393

393394
// Allow coalescing of a GR128 subreg COPY only if the subreg liverange is
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# RUN: llc -mtriple=s390x-linux-gnu -mcpu=z13 -O3 -start-before=livevars %s
2+
#
3+
# Test that coalesing of an empty live range (undef) does not cause failure.
4+
5+
--- |
6+
define dso_local void @fun(ptr %src, ptr %dst) #0 {
7+
%1 = sdiv i64 poison, poison
8+
%2 = load i32, ptr %src, align 4
9+
br i1 poison, label %6, label %3
10+
11+
3: ; preds = %0
12+
%4 = trunc i64 %1 to i32
13+
%5 = udiv i32 %4, %2
14+
br label %6
15+
16+
6: ; preds = %3, %0
17+
%7 = phi i32 [ %5, %3 ], [ 1, %0 ]
18+
store i32 %7, ptr %dst, align 4
19+
ret void
20+
}
21+
22+
...
23+
---
24+
name: fun
25+
alignment: 16
26+
tracksRegLiveness: true
27+
registers:
28+
- { id: 0, class: gr64bit }
29+
- { id: 1, class: gr32bit }
30+
- { id: 2, class: grx32bit }
31+
- { id: 3, class: grx32bit }
32+
- { id: 4, class: addr64bit }
33+
- { id: 5, class: addr64bit }
34+
- { id: 6, class: grx32bit }
35+
- { id: 7, class: grx32bit }
36+
- { id: 8, class: grx32bit }
37+
- { id: 9, class: gr64bit }
38+
- { id: 10, class: gr64bit }
39+
- { id: 11, class: gr128bit }
40+
- { id: 12, class: gr128bit }
41+
- { id: 13, class: gr128bit }
42+
- { id: 14, class: gr128bit }
43+
- { id: 15, class: gr64bit }
44+
liveins:
45+
- { reg: '$r2d', virtual-reg: '%4' }
46+
- { reg: '$r3d', virtual-reg: '%5' }
47+
frameInfo:
48+
maxAlignment: 1
49+
machineFunctionInfo: {}
50+
body: |
51+
bb.0 (%ir-block.0):
52+
liveins: $r2d, $r3d
53+
54+
%5:addr64bit = COPY $r3d
55+
%4:addr64bit = COPY $r2d
56+
%6:grx32bit = LHIMux 1
57+
%7:grx32bit = LHIMux 0
58+
CHIMux killed %7, 0, implicit-def $cc
59+
BRC 14, 6, %bb.2, implicit $cc
60+
J %bb.1
61+
62+
bb.1 (%ir-block.3):
63+
%1:gr32bit = LMux %4, 0, $noreg :: (load (s32) from %ir.src)
64+
%15:gr64bit = LLILL 0
65+
%14:gr128bit = INSERT_SUBREG undef %13:gr128bit, %15, %subreg.subreg_h64
66+
%11:gr128bit = INSERT_SUBREG %14, undef %9:gr64bit, %subreg.subreg_l64
67+
%12:gr128bit = DLR %11, %1
68+
%2:grx32bit = COPY %12.subreg_ll32
69+
70+
bb.2 (%ir-block.6):
71+
%3:grx32bit = PHI %6, %bb.0, %2, %bb.1
72+
STMux %3, %5, 0, $noreg :: (store (s32) into %ir.dst)
73+
Return
74+
75+
...

0 commit comments

Comments
 (0)