Skip to content

Commit c3cbd27

Browse files
LU-JOHNarsenm
andauthored
[AMDGPU] Calc IsVALU correctly during UADDO/USUBO selection (#159814)
Fix two bugs. The first bug hid the second bug. 1. Calculate IsVALU correctly during UADDO/USUBO selection. IsVALU should be false if the carryout users are UADDO_CARRY/USUBO_CARRY. However instruction selection visits uses before defs, so the UADDO_CARRY/USUBO_CARRY nodes are normally (probably always) already converted to S_ADD_CO_PSEUDO/S_SUB_CO_PSEUDO. Fix to check for these machine opcodes. 2. Without this fix, UADDO/USUBO selection will always select the VALU instructions V_ADD_CO__U32_e64/V_SUB_CO_U32_e64. S_UADDO_PSEUDO/S_USUBO_PSEUDO were never selected in the CodeGen/AMDGPU tests. Thus, S_UADDO_PSEUDO/S_USUBO_PSEUDO cases were never hit in EmitInstrWithCustomInserter. The code generation for S_UADDO_PSEUDO/S_USUBO_PSEUDO had a bug where it could not handle code generation for 32-bit $scc_out. --------- Signed-off-by: John Lu <[email protected]> Co-authored-by: Matt Arsenault <[email protected]>
1 parent 62660e5 commit c3cbd27

File tree

12 files changed

+5753
-5136
lines changed

12 files changed

+5753
-5136
lines changed

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,17 @@ void AMDGPUDAGToDAGISel::SelectUADDO_USUBO(SDNode *N) {
10891089
for (SDNode::user_iterator UI = N->user_begin(), E = N->user_end(); UI != E;
10901090
++UI)
10911091
if (UI.getUse().getResNo() == 1) {
1092-
if ((IsAdd && (UI->getOpcode() != ISD::UADDO_CARRY)) ||
1093-
(!IsAdd && (UI->getOpcode() != ISD::USUBO_CARRY))) {
1094-
IsVALU = true;
1095-
break;
1092+
if (UI->isMachineOpcode()) {
1093+
if (UI->getMachineOpcode() !=
1094+
(IsAdd ? AMDGPU::S_ADD_CO_PSEUDO : AMDGPU::S_SUB_CO_PSEUDO)) {
1095+
IsVALU = true;
1096+
break;
1097+
}
1098+
} else {
1099+
if (UI->getOpcode() != (IsAdd ? ISD::UADDO_CARRY : ISD::USUBO_CARRY)) {
1100+
IsVALU = true;
1101+
break;
1102+
}
10961103
}
10971104
}
10981105

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5970,9 +5970,9 @@ SITargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
59705970
.add(Src1);
59715971
// clang-format on
59725972

5973-
BuildMI(*BB, MI, DL, TII->get(AMDGPU::S_CSELECT_B64), Dest1.getReg())
5974-
.addImm(1)
5975-
.addImm(0);
5973+
unsigned SelOpc =
5974+
Subtarget->isWave64() ? AMDGPU::S_CSELECT_B64 : AMDGPU::S_CSELECT_B32;
5975+
BuildMI(*BB, MI, DL, TII->get(SelOpc), Dest1.getReg()).addImm(-1).addImm(0);
59765976

59775977
MI.eraseFromParent();
59785978
return BB;

0 commit comments

Comments
 (0)