[llvm] [X86][CodeGen] Fix crash when commute operands of Instruction for code size (PR #79245)
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 20:14:48 PST 2024
================
@@ -2355,29 +2355,30 @@ MachineInstr *X86InstrInfo::commuteInstructionImpl(MachineInstr &MI, bool NewMI,
// If we're optimizing for size, try to use MOVSD/MOVSS.
if (MI.getParent()->getParent()->getFunction().hasOptSize()) {
unsigned Mask;
+ unsigned NewOpc;
switch (Opc) {
default:
llvm_unreachable("Unreachable!");
case X86::BLENDPDrri:
- Opc = X86::MOVSDrr;
+ NewOpc = X86::MOVSDrr;
Mask = 0x03;
break;
case X86::BLENDPSrri:
- Opc = X86::MOVSSrr;
+ NewOpc = X86::MOVSSrr;
Mask = 0x0F;
break;
case X86::VBLENDPDrri:
- Opc = X86::VMOVSDrr;
+ NewOpc = X86::VMOVSDrr;
Mask = 0x03;
break;
case X86::VBLENDPSrri:
- Opc = X86::VMOVSSrr;
+ NewOpc = X86::VMOVSSrr;
Mask = 0x0F;
break;
}
if ((MI.getOperand(3).getImm() ^ Mask) == 1) {
WorkingMI = CloneIfNew(MI);
- WorkingMI->setDesc(get(Opc));
+ WorkingMI->setDesc(get(NewOpc));
----------------
KanRobert wrote:
> But the `break` at line 2383 won't make it jumps to `fallthrough`
Yes. The problem is that if `MI.getOperand(3).getImm() ^ Mask) == 1` is `false`, the fallthrough will happen.
`break` at line 2383 is expected b/c `WorkingMI` is determined.
https://github.com/llvm/llvm-project/pull/79245
More information about the llvm-commits
mailing list