This is an archive of the discontinued LLVM Phabricator instance.

[mips][msa] Prevent output operand from commuting for dpadd_[su].df instructions
ClosedPublic

Authored by smaksimovic on Mar 10 2017, 7:38 AM.

Details

Summary

Implementation of TargetInstrInfo::findCommutedOpIndices for MIPS target, restricting commutativity to second and third operand only for dpaadd_[su].df instructions therein.

Prior to this change, there were cases where the vector that is to be added to the dot product of the other two could take a position other than the first one in the instruction, generating false output in the destination vector.

Such behavior has been noticed in the two functions generating v2i64 output values so far. Other ones may exhibit such behavior as well, just not for the vector operands which are present in the test at the moment.

Tests altered so that the function's first operand is a constant splat so that it can be loaded with a ldi instruction, since that is the case in which the erroneous instruction operand placement has occurred. We check that the register which is present in the ldi instruction is placed as the first operand in the corresponding dpadd instruction.

Diff Detail

Repository
rL LLVM

Event Timeline

smaksimovic created this revision.Mar 10 2017, 7:38 AM
sdardis edited edge metadata.Mar 14 2017, 6:18 AM

Hi, this patch is technically correct but it misses the case that the second and third operands to dpadd_(s|u).[hwd] are commutable.

Unfortunately, the instruction definition has the typical tied format of (set MSA128DOpnd:$wd, (int_mips_dpadd_s_d MSA128DOpnd:$wd_in, MSA128WOpnd:$ws, MSA128WOpnd:$wt). The two address pass commutes the $wd_in and $ws.

Rather than removing the isCommutable class from those instructions, can you have a look at implementing TargetInstrInfo::commuteInstructionImpl for MIPS and handling these cases there?

Thanks,
Simon

smaksimovic retitled this revision from [mips][msa] Disable commutativity for dpadd_[su].df instructions to [mips][msa] Prevent output operand from commuting for dpadd_[su].df instructions.

Hi Simon,

As per your suggestion, we've taken a look at TargetInstrInfo::commuteInstructionImpl and ended up reimplementing TargetInstrInfo::findCommutedOpIndices
for the MIPS target and handled our instructions there, keeping the isCommutable flag in the .td file.

The latter function is being called prior to the former, setting its parameters accordingly.

sdardis accepted this revision.Mar 20 2017, 9:22 AM

LGTM with inline comment addressed. Don't forget to update the patch message before committing.

lib/Target/Mips/MipsInstrInfo.cpp
522–525 ↗(On Diff #92146)

I don't think we need to assign to CommutableOpIdx here. For these 6 cases, we know that it is always operands 2 and 3 that can be commuted.

This revision is now accepted and ready to land.Mar 20 2017, 9:22 AM
smaksimovic edited the summary of this revision. (Show Details)Mar 21 2017, 7:36 AM
This revision was automatically updated to reflect the committed changes.