Skip to content

Commit fdf996f

Browse files
changpengdavid-salinas
authored andcommitted
[AMDGPU] Fix op_sel settings for v_cvt_scale32_* and v_cvt_sr_* (llvm#151286)
For OPF_OPSEL_SRCBYTE: Vector instruction uses OPSEL[1:0] to specify a byte select for the first source operand. So op_sel [0, 0], [1, 0], [0, 1] and [1, 1] should map to byte 0, 1, 2 and 3, respectively. For OPF_OPSEL_DSTBYTE: OPSEL is used as a destination byte select. OPSEL[2:3] specify which byte of the destination to write to. Note that the order of the bits is different from that of OPF_OPSEL_SRCBYT. So the mapping should be: op_sel [0, 0], [0, 1], [1, 0] and [1, 1] map to byte 0, 1, 2 and 3, respectively. Fixes: SWDEV-544901
1 parent 8357ccc commit fdf996f

File tree

5 files changed

+78
-77
lines changed

5 files changed

+78
-77
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6675,13 +6675,13 @@ void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_0_0(
66756675
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
66766676
assert(OpIdx >= 0 && "expected to match an immediate operand");
66776677
MIB.addImm(
6678-
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
6678+
(MI.getOperand(OpIdx).getImm() & 0x1) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
66796679
}
66806680

66816681
void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_0_1(
66826682
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
66836683
assert(OpIdx >= 0 && "expected to match an immediate operand");
6684-
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x2)
6684+
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x1)
66856685
? (int64_t)(SISrcMods::OP_SEL_0 | SISrcMods::DST_OP_SEL)
66866686
: (int64_t)SISrcMods::DST_OP_SEL);
66876687
}
@@ -6690,13 +6690,13 @@ void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_1_0(
66906690
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
66916691
assert(OpIdx >= 0 && "expected to match an immediate operand");
66926692
MIB.addImm(
6693-
(MI.getOperand(OpIdx).getImm() & 0x1) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
6693+
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
66946694
}
66956695

66966696
void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_1_1(
66976697
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
66986698
assert(OpIdx >= 0 && "expected to match an immediate operand");
6699-
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x1)
6699+
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x2)
67006700
? (int64_t)(SISrcMods::OP_SEL_0)
67016701
: 0);
67026702
}
@@ -6719,14 +6719,15 @@ void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_2_0(
67196719
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
67206720
assert(OpIdx >= 0 && "expected to match an immediate operand");
67216721
MIB.addImm(
6722-
(MI.getOperand(OpIdx).getImm() & 0x1) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
6722+
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
67236723
}
67246724

67256725
void AMDGPUInstructionSelector::renderDstSelToOpSel3XFormXForm(
67266726
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
67276727
assert(OpIdx >= 0 && "expected to match an immediate operand");
6728-
MIB.addImm(
6729-
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::DST_OP_SEL : 0);
6728+
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x1)
6729+
? (int64_t)SISrcMods::DST_OP_SEL
6730+
: 0);
67306731
}
67316732

67326733
void AMDGPUInstructionSelector::renderExtractCPol(MachineInstrBuilder &MIB,

llvm/lib/Target/AMDGPU/VOP3Instructions.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,10 @@ class SrcAndDstSelToOpSelXForm<int modifier_idx, bit dest_sel> : SDNodeXForm<tim
972972
unsigned Val = N->getZExtValue();
973973
unsigned New = 0;
974974
if (}] # modifier_idx # [{ == 0) {
975-
New = (}] # dest_sel # [{ == 1) ? ((Val & 0x2) ? (SISrcMods::OP_SEL_0 | SISrcMods::DST_OP_SEL) : SISrcMods::DST_OP_SEL)
976-
: ((Val & 0x2) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE);
975+
New = (}] # dest_sel # [{ == 1) ? ((Val & 0x1) ? (SISrcMods::OP_SEL_0 | SISrcMods::DST_OP_SEL) : SISrcMods::DST_OP_SEL)
976+
: ((Val & 0x1) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE);
977977
} else if (}] # modifier_idx # [{== 1 || }] # modifier_idx # [{ == 2) {
978-
New = (Val & 0x1) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE;
978+
New = (Val & 0x2) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE;
979979
}
980980
return CurDAG->getTargetConstant(New, SDLoc(N), MVT::i32);
981981
}]>;
@@ -1019,7 +1019,7 @@ def gi_SrcSelToOpSelXForm : GICustomOperandRenderer<"renderSrcSelToOpSelXForm">,
10191019
def DstSelToOpSel3XForm : SDNodeXForm<timm, [{
10201020
uint32_t V = N->getZExtValue();
10211021
return CurDAG->getTargetConstant(
1022-
(V & 0x2) ? SISrcMods::DST_OP_SEL : SISrcMods::NONE,
1022+
(V & 0x1) ? SISrcMods::DST_OP_SEL : SISrcMods::NONE,
10231023
SDLoc(N), MVT::i32);
10241024
}]>;
10251025
def gi_DstSelToOpSel3XForm : GICustomOperandRenderer<"renderDstSelToOpSel3XFormXForm">,

0 commit comments

Comments
 (0)