Skip to content

Commit 7f91f1c

Browse files
committed
[X86] Fix decoding for vinsertps immediate operand
The relevant bit from the Intel SDM for vinsertps semantics: ``` IF (SRC = REG) THEN COUNT_S := imm8[7:6] ELSE COUNT_S := 0 ``` This is now taken into account.
1 parent b49c4af commit 7f91f1c

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,15 +1122,21 @@ bool llvm::EmitAnyX86InstComments(const MCInst *MI, raw_ostream &OS,
11221122
case X86::VINSERTPSrri:
11231123
case X86::VINSERTPSZrri:
11241124
Src2Name = getRegName(MI->getOperand(2).getReg());
1125-
[[fallthrough]];
1125+
DestName = getRegName(MI->getOperand(0).getReg());
1126+
Src1Name = getRegName(MI->getOperand(1).getReg());
1127+
if (MI->getOperand(NumOperands - 1).isImm())
1128+
DecodeINSERTPSMask(MI->getOperand(NumOperands - 1).getImm(),
1129+
ShuffleMask, false);
1130+
break;
1131+
11261132
case X86::INSERTPSrmi:
11271133
case X86::VINSERTPSrmi:
11281134
case X86::VINSERTPSZrmi:
11291135
DestName = getRegName(MI->getOperand(0).getReg());
11301136
Src1Name = getRegName(MI->getOperand(1).getReg());
11311137
if (MI->getOperand(NumOperands - 1).isImm())
11321138
DecodeINSERTPSMask(MI->getOperand(NumOperands - 1).getImm(),
1133-
ShuffleMask);
1139+
ShuffleMask, true);
11341140
break;
11351141

11361142
case X86::MOVLHPSrr:

llvm/lib/Target/X86/MCTargetDesc/X86ShuffleDecode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace llvm {
2525

26-
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask) {
26+
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask, bool SrcIsMem) {
2727
// Defaults the copying the dest value.
2828
ShuffleMask.push_back(0);
2929
ShuffleMask.push_back(1);
@@ -33,7 +33,7 @@ void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask) {
3333
// Decode the immediate.
3434
unsigned ZMask = Imm & 15;
3535
unsigned CountD = (Imm >> 4) & 3;
36-
unsigned CountS = (Imm >> 6) & 3;
36+
unsigned CountS = SrcIsMem ? 0 : (Imm >> 6) & 3;
3737

3838
// CountS selects which input element to use.
3939
unsigned InVal = 4 + CountS;

llvm/lib/Target/X86/MCTargetDesc/X86ShuffleDecode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ template <typename T> class SmallVectorImpl;
2828
enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
2929

3030
/// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
31-
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
31+
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask, bool SrcIsMem);
3232

3333
// Insert the bottom Len elements from a second source into a vector starting at
3434
// element Idx.

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5362,7 +5362,7 @@ static bool getTargetShuffleMask(SDValue N, bool AllowSentinelZero,
53625362
assert(N.getOperand(0).getValueType() == VT && "Unexpected value type");
53635363
assert(N.getOperand(1).getValueType() == VT && "Unexpected value type");
53645364
ImmN = N.getConstantOperandVal(N.getNumOperands() - 1);
5365-
DecodeINSERTPSMask(ImmN, Mask);
5365+
DecodeINSERTPSMask(ImmN, Mask, false);
53665366
IsUnary = IsFakeUnary = N.getOperand(0) == N.getOperand(1);
53675367
break;
53685368
case X86ISD::EXTRQI:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: llvm-mc -triple x86_64-unknown-unknown %s | FileCheck %s
2+
3+
.intel_syntax
4+
5+
# CHECK: vinsertps {{.*}} # xmm2 = xmm2[0,1,2],mem[0]
6+
7+
vinsertps xmm2,xmm2,dword ptr [r14+rdi*8+0x4C],0x0B0

0 commit comments

Comments
 (0)