From 3706bdad4ae0fe91fbb8bb3e0acc88cf6b13ce56 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 28 Jun 2022 09:07:23 -0700 Subject: [PATCH] [X86] Remove unnecessary COPY from EmitLoweredCascadedSelect. I believe we already checked that the destination of the first CMOV is only used by the second CMOV so I don't think there is any reason we need the PHI to write the register that was used by the first CMOV. We can directly use the second CMOV destination and avoid the copy. This may be a left over from when the cascaded select handling was part of the main algorithm before it was refactored in D35685. Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D128124 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index a124d14f2b9d..af7af105d086 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -34554,7 +34554,7 @@ X86TargetLowering::EmitLoweredCascadedSelect(MachineInstr &FirstCMOV, // SinkMBB: // %Result = phi [ %FalseValue, SecondInsertedMBB ], [ %TrueValue, ThisMBB ] - Register DestReg = FirstCMOV.getOperand(0).getReg(); + Register DestReg = SecondCascadedCMOV.getOperand(0).getReg(); Register Op1Reg = FirstCMOV.getOperand(1).getReg(); Register Op2Reg = FirstCMOV.getOperand(2).getReg(); MachineInstrBuilder MIB = @@ -34567,11 +34567,6 @@ X86TargetLowering::EmitLoweredCascadedSelect(MachineInstr &FirstCMOV, // The second SecondInsertedMBB provides the same incoming value as the // FirstInsertedMBB (the True operand of the SELECT_CC/CMOV nodes). MIB.addReg(FirstCMOV.getOperand(2).getReg()).addMBB(FirstInsertedMBB); - // Copy the PHI result to the register defined by the second CMOV. - BuildMI(*SinkMBB, std::next(MachineBasicBlock::iterator(MIB.getInstr())), DL, - TII->get(TargetOpcode::COPY), - SecondCascadedCMOV.getOperand(0).getReg()) - .addReg(FirstCMOV.getOperand(0).getReg()); // Now remove the CMOVs. FirstCMOV.eraseFromParent(); -- 2.34.1