Skip to content

Commit 394636c

Browse files
changpengkrishna2803
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 e3cf511 commit 394636c

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
@@ -6994,13 +6994,13 @@ void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_0_0(
69946994
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
69956995
assert(OpIdx >= 0 && "expected to match an immediate operand");
69966996
MIB.addImm(
6997-
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
6997+
(MI.getOperand(OpIdx).getImm() & 0x1) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
69986998
}
69996999

70007000
void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_0_1(
70017001
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
70027002
assert(OpIdx >= 0 && "expected to match an immediate operand");
7003-
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x2)
7003+
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x1)
70047004
? (int64_t)(SISrcMods::OP_SEL_0 | SISrcMods::DST_OP_SEL)
70057005
: (int64_t)SISrcMods::DST_OP_SEL);
70067006
}
@@ -7009,13 +7009,13 @@ void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_1_0(
70097009
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
70107010
assert(OpIdx >= 0 && "expected to match an immediate operand");
70117011
MIB.addImm(
7012-
(MI.getOperand(OpIdx).getImm() & 0x1) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
7012+
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
70137013
}
70147014

70157015
void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_1_1(
70167016
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
70177017
assert(OpIdx >= 0 && "expected to match an immediate operand");
7018-
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x1)
7018+
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x2)
70197019
? (int64_t)(SISrcMods::OP_SEL_0)
70207020
: 0);
70217021
}
@@ -7038,14 +7038,15 @@ void AMDGPUInstructionSelector::renderSrcAndDstSelToOpSelXForm_2_0(
70387038
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
70397039
assert(OpIdx >= 0 && "expected to match an immediate operand");
70407040
MIB.addImm(
7041-
(MI.getOperand(OpIdx).getImm() & 0x1) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
7041+
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::OP_SEL_0 : 0);
70427042
}
70437043

70447044
void AMDGPUInstructionSelector::renderDstSelToOpSel3XFormXForm(
70457045
MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const {
70467046
assert(OpIdx >= 0 && "expected to match an immediate operand");
7047-
MIB.addImm(
7048-
(MI.getOperand(OpIdx).getImm() & 0x2) ? (int64_t)SISrcMods::DST_OP_SEL : 0);
7047+
MIB.addImm((MI.getOperand(OpIdx).getImm() & 0x1)
7048+
? (int64_t)SISrcMods::DST_OP_SEL
7049+
: 0);
70497050
}
70507051

70517052
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
@@ -999,10 +999,10 @@ class SrcAndDstSelToOpSelXForm<int modifier_idx, bit dest_sel> : SDNodeXForm<tim
999999
unsigned Val = N->getZExtValue();
10001000
unsigned New = 0;
10011001
if (}] # modifier_idx # [{ == 0) {
1002-
New = (}] # dest_sel # [{ == 1) ? ((Val & 0x2) ? (SISrcMods::OP_SEL_0 | SISrcMods::DST_OP_SEL) : SISrcMods::DST_OP_SEL)
1003-
: ((Val & 0x2) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE);
1002+
New = (}] # dest_sel # [{ == 1) ? ((Val & 0x1) ? (SISrcMods::OP_SEL_0 | SISrcMods::DST_OP_SEL) : SISrcMods::DST_OP_SEL)
1003+
: ((Val & 0x1) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE);
10041004
} else if (}] # modifier_idx # [{== 1 || }] # modifier_idx # [{ == 2) {
1005-
New = (Val & 0x1) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE;
1005+
New = (Val & 0x2) ? SISrcMods::OP_SEL_0 : SISrcMods::NONE;
10061006
}
10071007
return CurDAG->getTargetConstant(New, SDLoc(N), MVT::i32);
10081008
}]>;
@@ -1046,7 +1046,7 @@ def gi_SrcSelToOpSelXForm : GICustomOperandRenderer<"renderSrcSelToOpSelXForm">,
10461046
def DstSelToOpSel3XForm : SDNodeXForm<timm, [{
10471047
uint32_t V = N->getZExtValue();
10481048
return CurDAG->getTargetConstant(
1049-
(V & 0x2) ? SISrcMods::DST_OP_SEL : SISrcMods::NONE,
1049+
(V & 0x1) ? SISrcMods::DST_OP_SEL : SISrcMods::NONE,
10501050
SDLoc(N), MVT::i32);
10511051
}]>;
10521052
def gi_DstSelToOpSel3XForm : GICustomOperandRenderer<"renderDstSelToOpSel3XFormXForm">,

0 commit comments

Comments
 (0)