Skip to content

Commit 4ea1791

Browse files
[X86] Truncate unused bit for blendw mask (llvm#178883)
While tuning ProcessBLENDWToBLENDD https://github.com/mahesh-attarde/llvm-project/blob/07ec2fa1443ccd3cbb55612937f1dddebfe51c15/llvm/lib/Target/X86/X86FixupInstTuning.cpp#L262 we creating mask from `getImm()` which returns 64bit int and APInt accept 64 bit int. ``` APInt MaskW = APInt(8, MI.getOperand(NumOperands - 1).getImm(), /*IsSigned=*/false); ``` It fails with MIR for BLENDW instruction that requires8 bit mask 0xAA from 64 bit Imm. ``` renamable $xmm2 = VPBLENDWrri renamable $xmm1, killed renamable $xmm2, -86 ``` APInt construction complains since higher bits of are also set for transformations where mask bits are set (results in negative values). https://github.com/mahesh-attarde/llvm-project/blob/07ec2fa1443ccd3cbb55612937f1dddebfe51c15/llvm/include/llvm/ADT/APInt.h#L125 This patch uses implictTruncate from APInt constructor to get around. other approach could have been using direct mask(same effect as implicit truncate) `AND` with Imm or use signed version (not applicable since mask). This case was generate using bisect so most of test excercises, i tried with VPBLEND generating IR refuse to generate mask in range 0b10101010, so patch lacks test.
1 parent e438a90 commit 4ea1791

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/Target/X86/X86FixupInstTuning.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ bool X86FixupInstTuningImpl::processInstruction(
260260
return false;
261261
// Convert to VPBLENDD if scaling the VPBLENDW mask down/up loses no bits.
262262
APInt MaskW =
263-
APInt(8, MI.getOperand(NumOperands - 1).getImm(), /*IsSigned=*/false);
263+
APInt(8, MI.getOperand(NumOperands - 1).getImm(), /*IsSigned=*/false,
264+
/*implicitTrunc=*/true);
264265
APInt MaskD = APIntOps::ScaleBitMask(MaskW, 4, /*MatchAllBits=*/true);
265266
if (MaskW != APIntOps::ScaleBitMask(MaskD, 8, /*MatchAllBits=*/true))
266267
return false;

0 commit comments

Comments
 (0)