Skip to content

Commit bc747c3

Browse files
tltaoTony Tao
andauthored
[SystemZ][z/OS] Fix incorrect codegen for ADA_ENTRY pseudo instruction (#101415)
The current MCInstBuilder for generating an ALGFI when loading something from the ADA is incorrect and will crash the compiler. r0 must also be excluded from the registers returned as the result, since it is treated as the value "0" on z/OS. Also add some tests to properly test the paths where LLILF and ALGFI are generated. --------- Co-authored-by: Tony Tao <[email protected]>
1 parent d68a4d5 commit bc747c3

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,10 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
346346
*OutStreamer,
347347
MCInstBuilder(SystemZ::LLILF).addReg(TargetReg).addImm(Disp));
348348
} else
349-
EmitToStreamer(
350-
*OutStreamer,
351-
MCInstBuilder(SystemZ::ALGFI).addReg(TargetReg).addImm(Disp));
349+
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::ALGFI)
350+
.addReg(TargetReg)
351+
.addReg(TargetReg)
352+
.addImm(Disp));
352353
Disp = 0;
353354
Op = Op0;
354355
}

llvm/lib/Target/SystemZ/SystemZInstrInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ let Predicates = [IsTargetXPLINK64] in {
298298
}
299299

300300
let hasNoSchedulingInfo = 1, Defs = [CC] in {
301-
def ADA_ENTRY : Alias<12, (outs GR64:$Reg), (ins adasym:$addr,
301+
def ADA_ENTRY : Alias<12, (outs ADDR64:$Reg), (ins adasym:$addr,
302302
ADDR64:$ADA, imm64:$Offset),
303303
[(set i64:$Reg, (z_ada_entry i64:$addr,
304304
i64:$ADA, i64:$Offset))]>;
305305
}
306306
let mayLoad = 1, AddedComplexity = 20, hasNoSchedulingInfo = 1, Defs = [CC] in {
307-
def ADA_ENTRY_VALUE : Alias<12, (outs GR64:$Reg), (ins adasym:$addr,
307+
def ADA_ENTRY_VALUE : Alias<12, (outs ADDR64:$Reg), (ins adasym:$addr,
308308
ADDR64:$ADA, imm64:$Offset),
309309
[(set i64:$Reg, (z_load (z_ada_entry
310310
iPTR:$addr, iPTR:$ADA, i64:$Offset)))]>;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test code generation for retrieving function descriptors
2+
# from the ADA when the ADA is extremely large and forces the
3+
# generation of a different instruction sequence
4+
# RUN: %python %s | llc -mtriple=s390x-ibm-zos -O2 | FileCheck %s
5+
6+
# CHECK: llilf 1, {{[0-9]+}}
7+
# CHECK-NEXT: la 1, 0(1,8)
8+
9+
from __future__ import print_function
10+
11+
num_calls = 35000
12+
13+
print("define hidden signext i32 @main() {")
14+
print("entry:")
15+
16+
for i in range(num_calls):
17+
print(" call void @foo%d()" % i)
18+
19+
print(" call void @bar(ptr noundef @foo)")
20+
print("ret i32 0")
21+
print("}")
22+
23+
for i in range(num_calls):
24+
print("declare void @foo%d(...)" % i)
25+
26+
print("declare void @bar(ptr noundef)")
27+
print("define internal void @foo() {")
28+
print("entry:")
29+
print(" ret void")
30+
print(" }")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Test code generation for retrieving function descriptors
2+
# from the ADA when the ADA is extremely large and forces the
3+
# generation of a different instruction sequence
4+
# RUN: %python %s | llc -mtriple=s390x-ibm-zos -O2 | FileCheck %s
5+
6+
# CHECK: algfi 8, {{[0-9]+}}
7+
# CHECK: la 8, 0(8)
8+
9+
from __future__ import print_function
10+
11+
num_calls = 35000
12+
13+
print("define hidden signext i32 @main() {")
14+
print("entry:")
15+
16+
for i in range(num_calls):
17+
print(" call void @foo%d()" % i)
18+
19+
# This is added to force the use of register r8 to generate
20+
# la 8, 0(8) which generates the algfi instruction
21+
print('%0 = call ptr asm " LGR $0,$1\0A", "=r,{r8}"(ptr nonnull @foo)')
22+
print(" call void @bar(ptr noundef %0)")
23+
print("ret i32 0")
24+
print("}")
25+
26+
for i in range(num_calls):
27+
print("declare void @foo%d(...)" % i)
28+
29+
print("declare void @bar(ptr noundef)")
30+
print("define internal void @foo() {")
31+
print("entry:")
32+
print(" ret void")
33+
print(" }")

0 commit comments

Comments
 (0)