Skip to content

[AMDGCN] Error checking for llvm.amdgcn.init.exec.from.input intrinsic #128176

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

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,21 @@ void SIWholeQuadMode::lowerInitExec(MachineInstr &MI) {
MachineInstr *FirstMI = &*MBB->begin();
if (InputReg.isVirtual()) {
MachineInstr *DefInstr = MRI->getVRegDef(InputReg);
assert(DefInstr && DefInstr->isCopy());
// This condition catches some cases where a
// llvm.amdgcn.init.exec.from.input intrinsic's first argument comes from
// somewhere other than a (SGPR) function argument, which is forbidden.
if (!DefInstr || !DefInstr->isCopy() ||
(DefInstr->getNumOperands() == 2 && DefInstr->getOperand(1).isReg() &&
TRI->isVectorRegister(*MRI, DefInstr->getOperand(1).getReg()))) {
MachineFunction *MF = MBB->getParent();
DebugLoc DL = DefInstr->getDebugLoc();
DiagnosticInfoUnsupported IllegalArg(
MF->getFunction(), "EXEC must be initialized using function argument",
DL, DS_Error);
LLVMContext &C = MF->getFunction().getContext();
C.diagnose(IllegalArg);
return;
Comment on lines +1625 to +1638
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs in the machine verifier, and does not need to be a proper error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need machine verification of this? I think the IR would be enough

}
if (DefInstr->getParent() == MBB) {
if (DefInstr != FirstMI) {
// If the `InputReg` is defined in current block, we also need to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; RUN: not llc -mtriple=amdgcn -mcpu=gfx942 -O3 -global-isel=true -o - %s 2>&1 | FileCheck -check-prefix=ERR %s

source_filename = "llvm.amdgcn.init.exec.wave32.ll"

@G = global i32 -2147483648
@G.1 = global <32 x i32> splat (i32 1)
@G.2 = global <16 x i64> splat (i64 1)
@G.3 = global <8 x i1> zeroinitializer

define amdgpu_ps float @test_init_exec(float %a, float %b) {
main_body:
%s = fadd float %a, %b
call void @llvm.amdgcn.init.exec(i64 74565)
ret float %s
}

define amdgpu_ps float @test_init_exec_from_input(i32 inreg %0, i32 inreg %1, i32 inreg %2, i32 inreg %count, float %a, float %b) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have failed the IR verifier

main_body:
%LGV2 = load <16 x i64>, ptr @G.2, align 128
%LGV1 = load <32 x i32>, ptr @G.1, align 128
%LGV = load i32, ptr @G, align 4
%C = call <8 x i1> @f(<32 x i32> %LGV1, <16 x i64> %LGV2, <2 x half> splat (half 0xH5140))
%B = or i32 0, %LGV
%s = fadd float %a, %b
call void @llvm.amdgcn.init.exec.from.input(i32 %B, i32 8)
store <8 x i1> %C, ptr @G.3, align 1
ret float %s
}

; Function Attrs: convergent nocallback nofree nounwind willreturn
declare void @llvm.amdgcn.init.exec(i64 immarg) #0

; Function Attrs: convergent nocallback nofree nounwind willreturn
declare void @llvm.amdgcn.init.exec.from.input(i32, i32 immarg) #0

declare <8 x i1> @f(<32 x i32>, <16 x i64>, <2 x half>)

attributes #0 = { convergent nocallback nofree nounwind willreturn }

ERR: error: <unknown>:0:0: in function test_init_exec_from_input float (i32, i32, i32, i32, float, float): EXEC must be initialized using function argument
40 changes: 40 additions & 0 deletions llvm/test/CodeGen/AMDGPU/intrinsic-initexecfrominput.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; RUN: not llc -mtriple=amdgcn -mcpu=gfx942 -O3 -global-isel=false -o - %s 2>&1 | FileCheck -check-prefix=ERR %s

source_filename = "llvm.amdgcn.init.exec.wave32.ll"

@G = global i32 -2147483648
@G.1 = global <32 x i32> splat (i32 1)
@G.2 = global <16 x i64> splat (i64 1)
@G.3 = global <8 x i1> zeroinitializer

define amdgpu_ps float @test_init_exec(float %a, float %b) {
main_body:
%s = fadd float %a, %b
call void @llvm.amdgcn.init.exec(i64 74565)
ret float %s
}

define amdgpu_ps float @test_init_exec_from_input(i32 inreg %0, i32 inreg %1, i32 inreg %2, i32 inreg %count, float %a, float %b) {
main_body:
%LGV2 = load <16 x i64>, ptr @G.2, align 128
%LGV1 = load <32 x i32>, ptr @G.1, align 128
%LGV = load i32, ptr @G, align 4
%C = call <8 x i1> @f(<32 x i32> %LGV1, <16 x i64> %LGV2, <2 x half> splat (half 0xH5140))
%B = or i32 0, %LGV
%s = fadd float %a, %b
call void @llvm.amdgcn.init.exec.from.input(i32 %B, i32 8)
store <8 x i1> %C, ptr @G.3, align 1
ret float %s
}

; Function Attrs: convergent nocallback nofree nounwind willreturn
declare void @llvm.amdgcn.init.exec(i64 immarg) #0

; Function Attrs: convergent nocallback nofree nounwind willreturn
declare void @llvm.amdgcn.init.exec.from.input(i32, i32 immarg) #0

declare <8 x i1> @f(<32 x i32>, <16 x i64>, <2 x half>)

attributes #0 = { convergent nocallback nofree nounwind willreturn }

ERR: error: <unknown>:0:0: in function test_init_exec_from_input float (i32, i32, i32, i32, float, float): EXEC must be initialized using function argument