Skip to content

Commit

Permalink
Add test and address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KanRobert committed Jan 24, 2024
1 parent fe617f4 commit aa659f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
38 changes: 15 additions & 23 deletions llvm/lib/Target/X86/X86InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2326,34 +2326,26 @@ MachineInstr *X86InstrInfo::commuteInstructionImpl(MachineInstr &MI, bool NewMI,
case X86::VBLENDPSrri:
// 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:
NewOpc = X86::MOVSDrr;
Mask = 0x03;
break;
case X86::BLENDPSrri:
NewOpc = X86::MOVSSrr;
Mask = 0x0F;
break;
case X86::VBLENDPDrri:
NewOpc = X86::VMOVSDrr;
Mask = 0x03;
break;
case X86::VBLENDPSrri:
NewOpc = X86::VMOVSSrr;
Mask = 0x0F;
break;
}
unsigned Mask = (Opc == X86::BLENDPDrri || Opc == X86::VBLENDPDrri) ? 0x03: 0x0F;
if ((MI.getOperand(3).getImm() ^ Mask) == 1) {
#define FROM_TO(A, B) \
case X86::A: \
Opc = X86::B; \
break;
switch (Opc) {
default:
llvm_unreachable("Unreachable!");
FROM_TO(BLENDPDrri, MOVSDrr)
FROM_TO(BLENDPSrri, MOVSSrr)
FROM_TO(VBLENDPDrri, VMOVSDrr)
FROM_TO(VBLENDPSrri, VMOVSSrr)
}
WorkingMI = CloneIfNew(MI);
WorkingMI->setDesc(get(NewOpc));
WorkingMI->setDesc(get(Opc));
WorkingMI->removeOperand(3);
break;
}
#undef FROM_TO
}
[[fallthrough]];
case X86::PBLENDWrri:
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/CodeGen/X86/commute-blend-avx2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ define <4 x double> @commute_fold_vblendpd_256(<4 x double> %a, ptr %b) #0 {
ret <4 x double> %2
}
declare <4 x double> @llvm.x86.avx.blend.pd.256(<4 x double>, <4 x double>, i8) nounwind readnone

define <4 x float> @commute_vblendpd_128_for_code_size(<4 x float> %a, <4 x float> %b) optsize {
; CHECK-LABEL: commute_vblendpd_128_for_code_size:
; CHECK: # %bb.0:
; CHECK-NEXT: vblendps {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2,3]
; CHECK-NEXT: retq
%r = shufflevector <4 x float> %b, <4 x float> %a, <4 x i32> <i32 0, i32 5, i32 2, i32 3>
ret <4 x float> %r
}

0 comments on commit aa659f1

Please sign in to comment.