From dc185522fbdec75490cacfaa15966c4a2a7505d2 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 23 Feb 2019 21:41:44 +0000 Subject: [TwoAddressInstructionPass] After commuting an instruction and before trying to look for more commutable operands, resample the number of operands. The new instruciton might have less operands than the original instruction. If we don't resample, the next loop iteration might read an operand that doesn't exist. X86 can commute blends to movss/movsd which reduces from 4 operands to 3. This happened in the test case that caused r354363 & company to be reverted. A reduced version of that has been committed here. Really this whole checking for more commutable operands is a little fragile. It assumes that the new instructions operands are the same order and positions as the original except for the pair that was swapped. I don't know of anything that breaks this assumption today, but I've left a fixme. Fixing this will likely require an interface change. llvm-svn: 354738 --- llvm/lib/CodeGen/TwoAddressInstructionPass.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/CodeGen/TwoAddressInstructionPass.cpp') diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp index 737d01eaa17..43d87664696 100644 --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -1244,8 +1244,13 @@ bool TwoAddressInstructionPass::tryInstructionCommute(MachineInstr *MI, ++NumAggrCommuted; // There might be more than two commutable operands, update BaseOp and // continue scanning. + // FIXME: This assumes that the new instruction's operands are in the + // same positions and were simply swapped. BaseOpReg = OtherOpReg; BaseOpKilled = OtherOpKilled; + // Resamples OpsNum in case the number of operands was reduced. This + // happens with X86. + OpsNum = MI->getDesc().getNumOperands(); continue; } // If this was a commute based on kill, we won't do better continuing. -- cgit v1.2.3