[AMDGPU][GlobalISel]selectImpl() may create illegal copy from VGPR to SGPR
This is found during investigation of issue https://github.com/llvm/llvm-project/issues/61468
After importing more td patterns to global MatchTable, for example the patterns in https://reviews.llvm.org/D147780, selectImpl() will create illegal copy.
For now in https://reviews.llvm.org/D147780, this issue is workaround by not using selectImpl() to do the selection. But maybe a fix in selectImpl() should be made to avoid such issue.
@llvm/issue-subscribers-backend-amdgpu
I am interested in this issue. Can someone assign to me.
There's been a number of changes to boolean handling since this was filed. cc @petar-avramovic
Is there a .ll test for this? This probably has to be fixed before instruction-select, maybe something like: https://github.com/llvm/llvm-project/pull/68858 If not and we want to select it intentionally as vgpr to sgpr copy we need to make use of uniformity info analysis first in https://github.com/llvm/llvm-project/pull/73684
Sorry for the delay. Totally lost track for this issue.
To reproduce the bug, try following change and run ninja check-llvm:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
index dcb0f47973c4..9be4b6744cc1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
@@ -3609,8 +3609,9 @@ bool AMDGPUInstructionSelector::select(MachineInstr &I) {
// This is a workaround. For extension from type i1, `selectImpl()` uses
// patterns from TD file and generates an illegal VGPR to SGPR COPY as type
// i1 can only be hold in a SGPR class.
- if (MRI->getType(I.getOperand(1).getReg()) != LLT::scalar(1) &&
- selectImpl(I, *CoverageInfo))
+ //if (MRI->getType(I.getOperand(1).getReg()) != LLT::scalar(1) &&
+ // selectImpl(I, *CoverageInfo))
+ if (selectImpl(I, *CoverageInfo))
return true;
return selectG_SZA_EXT(I);
case TargetOpcode::G_FPEXT:
ninja check-llvm -j128
Failed Tests (9):
LLVM :: CodeGen/AMDGPU/GlobalISel/divergence-divergent-i1-phis-no-lane-mask-merging.ll
LLVM :: CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll
LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-anyext.mir
LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-freeze.mir
LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-icmp.s64.mir
LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-sext.mir
LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-zext.mir
LLVM :: CodeGen/AMDGPU/div_i128.ll
LLVM :: CodeGen/AMDGPU/div_v2i128.ll
an error:
FileCheck -check-prefix=GFX10 llvm-project/llvm/test/CodeGen/AMDGPU/GlobalISel/divergence-temporal-divergent-i1.ll
error: <unknown>:0:0: in function temporal_divergent_i1_phi void (float, ptr): illegal VGPR to SGPR copy
error: <unknown>:0:0: in function temporal_divergent_i1_phi void (float, ptr): illegal VGPR to SGPR copy
error: <unknown>:0:0: in function temporal_divergent_i1_non_phi void (float, ptr): illegal VGPR to SGPR copy
error: <unknown>:0:0: in function temporal_divergent_i1_non_phi void (float, ptr): illegal VGPR to SGPR copy
Thank you @chenzheng1030 ! I have been really busy lately, but when I have a chance I would like to circle back to this issue if no one else has picked it up.