From 00bbda07ae8b4d9a844fac1851ed8d70ef9bea76 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Fri, 28 Jan 2022 11:07:58 +0000 Subject: [PATCH] [AMDGPU] SILoadStoreOptimizer: simplify class/subclass checks Also add a comment explaining the difference between class and subclass. NFCI. --- llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp | 28 +++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp b/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp index 1e25c15..42fc927 100644 --- a/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp +++ b/llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp @@ -390,7 +390,8 @@ static InstClassEnum getInstClass(unsigned Opc, const SIInstrInfo &TII) { } /// Determines instruction subclass from opcode. Only instructions -/// of the same subclass can be merged together. +/// of the same subclass can be merged together. The merged instruction may have +/// a different subclass but must have the same class. static unsigned getInstSubclass(unsigned Opc, const SIInstrInfo &TII) { switch (Opc) { default: @@ -893,22 +894,23 @@ SILoadStoreOptimizer::getDataRegClass(const MachineInstr &MI) const { bool SILoadStoreOptimizer::checkAndPrepareMerge( CombineInfo &CI, CombineInfo &Paired, SmallVectorImpl &InstsToMove) { + // If another instruction has already been merged into CI, it may now be a + // type that we can't do any further merging into. + if (CI.InstClass == UNKNOWN || Paired.InstClass == UNKNOWN) + return false; + assert(CI.InstClass == Paired.InstClass); // Check both offsets (or masks for MIMG) can be combined and fit in the // reduced range. - if (CI.InstClass == MIMG && !dmasksCanBeCombined(CI, *TII, Paired)) - return false; - - if (CI.InstClass != MIMG && - (!widthsFit(*STM, CI, Paired) || !offsetsCanBeCombined(CI, *STM, Paired))) - return false; + if (CI.InstClass == MIMG) { + if (!dmasksCanBeCombined(CI, *TII, Paired)) + return false; + } else { + if (!widthsFit(*STM, CI, Paired) || !offsetsCanBeCombined(CI, *STM, Paired)) + return false; + } const unsigned Opc = CI.I->getOpcode(); - const InstClassEnum InstClass = getInstClass(Opc, *TII); - - if (InstClass == UNKNOWN) { - return false; - } const unsigned InstSubclass = getInstSubclass(Opc, *TII); DenseSet RegDefsToMove; @@ -930,7 +932,7 @@ bool SILoadStoreOptimizer::checkAndPrepareMerge( return false; } - if ((getInstClass(MBBI->getOpcode(), *TII) != InstClass) || + if ((getInstClass(MBBI->getOpcode(), *TII) != CI.InstClass) || (getInstSubclass(MBBI->getOpcode(), *TII) != InstSubclass)) { // This is not a matching instruction, but we can keep looking as // long as one of these conditions are met: -- 2.7.4