Skip to content

[SystemZ][z/OS] Fix incorrect codegen for ADA_ENTRY pseudo instruction #101415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ void SystemZAsmPrinter::emitInstruction(const MachineInstr *MI) {
*OutStreamer,
MCInstBuilder(SystemZ::LLILF).addReg(TargetReg).addImm(Disp));
} else
EmitToStreamer(
*OutStreamer,
MCInstBuilder(SystemZ::ALGFI).addReg(TargetReg).addImm(Disp));
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::ALGFI)
.addReg(TargetReg)
.addReg(TargetReg)
.addImm(Disp));
Disp = 0;
Op = Op0;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/SystemZ/SystemZInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ let Predicates = [IsTargetXPLINK64] in {
}

let hasNoSchedulingInfo = 1, Defs = [CC] in {
def ADA_ENTRY : Alias<12, (outs GR64:$Reg), (ins adasym:$addr,
def ADA_ENTRY : Alias<12, (outs ADDR64:$Reg), (ins adasym:$addr,
ADDR64:$ADA, imm64:$Offset),
[(set i64:$Reg, (z_ada_entry i64:$addr,
i64:$ADA, i64:$Offset))]>;
}
let mayLoad = 1, AddedComplexity = 20, hasNoSchedulingInfo = 1, Defs = [CC] in {
def ADA_ENTRY_VALUE : Alias<12, (outs GR64:$Reg), (ins adasym:$addr,
def ADA_ENTRY_VALUE : Alias<12, (outs ADDR64:$Reg), (ins adasym:$addr,
ADDR64:$ADA, imm64:$Offset),
[(set i64:$Reg, (z_load (z_ada_entry
iPTR:$addr, iPTR:$ADA, i64:$Offset)))]>;
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/CodeGen/SystemZ/Large/large-ada-01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Test code generation for retrieving function descriptors
# from the ADA when the ADA is extremely large and forces the
# generation of a different instruction sequence
# RUN: %python %s | llc -mtriple=s390x-ibm-zos -O2 | FileCheck %s

# CHECK: llilf 1, {{[0-9]+}}
# CHECK-NEXT: la 1, 0(1,8)

from __future__ import print_function

num_calls = 35000

print("define hidden signext i32 @main() {")
print("entry:")

for i in range(num_calls):
print(" call void @foo%d()" % i)

print(" call void @bar(ptr noundef @foo)")
print("ret i32 0")
print("}")

for i in range(num_calls):
print("declare void @foo%d(...)" % i)

print("declare void @bar(ptr noundef)")
print("define internal void @foo() {")
print("entry:")
print(" ret void")
print(" }")
33 changes: 33 additions & 0 deletions llvm/test/CodeGen/SystemZ/Large/large-ada-02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Test code generation for retrieving function descriptors
# from the ADA when the ADA is extremely large and forces the
# generation of a different instruction sequence
# RUN: %python %s | llc -mtriple=s390x-ibm-zos -O2 | FileCheck %s

# CHECK: algfi 8, {{[0-9]+}}
# CHECK: la 8, 0(8)

from __future__ import print_function

num_calls = 35000

print("define hidden signext i32 @main() {")
print("entry:")

for i in range(num_calls):
print(" call void @foo%d()" % i)

# This is added to force the use of register r8 to generate
# la 8, 0(8) which generates the algfi instruction
print('%0 = call ptr asm " LGR $0,$1\0A", "=r,{r8}"(ptr nonnull @foo)')
print(" call void @bar(ptr noundef %0)")
print("ret i32 0")
print("}")

for i in range(num_calls):
print("declare void @foo%d(...)" % i)

print("declare void @bar(ptr noundef)")
print("define internal void @foo() {")
print("entry:")
print(" ret void")
print(" }")
Loading