Skip to content

Commit 7089c01

Browse files
committed
[X86][NFC] Replace if-else with switch-case in X86InstrInfo::foldMemoryOperandImpl
1 parent 6754b54 commit 7089c01

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7891,10 +7891,11 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
78917891

78927892
// Determine the alignment of the load.
78937893
Align Alignment;
7894+
unsigned LoadOpc = LoadMI.getOpcode();
78947895
if (LoadMI.hasOneMemOperand())
78957896
Alignment = (*LoadMI.memoperands_begin())->getAlign();
78967897
else
7897-
switch (LoadMI.getOpcode()) {
7898+
switch (LoadOpc) {
78987899
case X86::AVX512_512_SET0:
78997900
case X86::AVX512_512_SETALLONES:
79007901
Alignment = Align(64);
@@ -7958,7 +7959,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
79587959
return nullptr;
79597960

79607961
SmallVector<MachineOperand, X86::AddrNumOperands> MOs;
7961-
switch (LoadMI.getOpcode()) {
7962+
switch (LoadOpc) {
79627963
case X86::MMX_SET0:
79637964
case X86::V_SET0:
79647965
case X86::V_SETALLONES:
@@ -8001,32 +8002,55 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
80018002
// Create a constant-pool entry.
80028003
MachineConstantPool &MCP = *MF.getConstantPool();
80038004
Type *Ty;
8004-
unsigned Opc = LoadMI.getOpcode();
8005-
if (Opc == X86::FsFLD0SS || Opc == X86::AVX512_FsFLD0SS)
8005+
bool IsAllOnes = false;
8006+
switch (LoadOpc) {
8007+
case X86::FsFLD0SS:
8008+
case X86::AVX512_FsFLD0SS:
80068009
Ty = Type::getFloatTy(MF.getFunction().getContext());
8007-
else if (Opc == X86::FsFLD0SD || Opc == X86::AVX512_FsFLD0SD)
8010+
break;
8011+
case X86::FsFLD0SD:
8012+
case X86::AVX512_FsFLD0SD:
80088013
Ty = Type::getDoubleTy(MF.getFunction().getContext());
8009-
else if (Opc == X86::FsFLD0F128 || Opc == X86::AVX512_FsFLD0F128)
8014+
break;
8015+
case X86::FsFLD0F128:
8016+
case X86::AVX512_FsFLD0F128:
80108017
Ty = Type::getFP128Ty(MF.getFunction().getContext());
8011-
else if (Opc == X86::FsFLD0SH || Opc == X86::AVX512_FsFLD0SH)
8018+
break;
8019+
case X86::FsFLD0SH:
8020+
case X86::AVX512_FsFLD0SH:
80128021
Ty = Type::getHalfTy(MF.getFunction().getContext());
8013-
else if (Opc == X86::AVX512_512_SET0 || Opc == X86::AVX512_512_SETALLONES)
8022+
break;
8023+
case X86::AVX512_512_SETALLONES:
8024+
IsAllOnes = true;
8025+
[[fallthrough]];
8026+
case X86::AVX512_512_SET0:
80148027
Ty = FixedVectorType::get(Type::getInt32Ty(MF.getFunction().getContext()),
80158028
16);
8016-
else if (Opc == X86::AVX2_SETALLONES || Opc == X86::AVX_SET0 ||
8017-
Opc == X86::AVX512_256_SET0 || Opc == X86::AVX1_SETALLONES)
8029+
break;
8030+
case X86::AVX1_SETALLONES:
8031+
case X86::AVX2_SETALLONES:
8032+
IsAllOnes = true;
8033+
[[fallthrough]];
8034+
case X86::AVX512_256_SET0:
8035+
case X86::AVX_SET0:
80188036
Ty = FixedVectorType::get(Type::getInt32Ty(MF.getFunction().getContext()),
80198037
8);
8020-
else if (Opc == X86::MMX_SET0)
8038+
8039+
break;
8040+
case X86::MMX_SET0:
80218041
Ty = FixedVectorType::get(Type::getInt32Ty(MF.getFunction().getContext()),
80228042
2);
8023-
else
8043+
break;
8044+
case X86::V_SETALLONES:
8045+
IsAllOnes = true;
8046+
[[fallthrough]];
8047+
case X86::V_SET0:
8048+
case X86::AVX512_128_SET0:
80248049
Ty = FixedVectorType::get(Type::getInt32Ty(MF.getFunction().getContext()),
80258050
4);
8051+
break;
8052+
}
80268053

8027-
bool IsAllOnes =
8028-
(Opc == X86::V_SETALLONES || Opc == X86::AVX2_SETALLONES ||
8029-
Opc == X86::AVX512_512_SETALLONES || Opc == X86::AVX1_SETALLONES);
80308054
const Constant *C =
80318055
IsAllOnes ? Constant::getAllOnesValue(Ty) : Constant::getNullValue(Ty);
80328056
unsigned CPI = MCP.getConstantPoolIndex(C, Alignment);

0 commit comments

Comments
 (0)