[llvm] 3bd15c0 - [AMDGPU] Fix adding modifiers when creating v_cmpx instructions.

Thomas Symalla via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 08:52:59 PDT 2022


Author: Thomas Symalla
Date: 2022-03-28T17:52:53+02:00
New Revision: 3bd15c03c6d864ebfb5d5cb8dc9672958ee41427

URL: https://github.com/llvm/llvm-project/commit/3bd15c03c6d864ebfb5d5cb8dc9672958ee41427
DIFF: https://github.com/llvm/llvm-project/commit/3bd15c03c6d864ebfb5d5cb8dc9672958ee41427.diff

LOG: [AMDGPU] Fix adding modifiers when creating v_cmpx instructions.

Revision https://reviews.llvm.org/D122332 added a pattern transformation
where v_cmpx instructions are introduced. However, the modifiers are
not correctly inherited from the original operands. The patch
adds the source modifiers, if they are exist, or sets them to 0.

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D122489

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
    llvm/test/CodeGen/AMDGPU/vcmp-saveexec-to-vcmpx.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp b/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
index e45642b934d28..e6e948c1242ef 100644
--- a/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
+++ b/llvm/lib/Target/AMDGPU/SIOptimizeExecMasking.cpp
@@ -451,20 +451,19 @@ static bool optimizeVCMPSaveExecSequence(MachineInstr &SaveExecInstr,
   auto Builder = BuildMI(*VCmp.getParent(), std::next(InsertPosIt),
                          VCmp.getDebugLoc(), TII->get(NewOpcode));
 
-  if (AMDGPU::getNamedOperandIdx(NewOpcode, AMDGPU::OpName::src0_modifiers) !=
-      -1)
-    Builder.addImm(0);
+  auto TryAddImmediateValueFromNamedOperand =
+      [&](unsigned OperandName) -> void {
+    if (auto *Mod = TII->getNamedOperand(VCmp, OperandName))
+      Builder.addImm(Mod->getImm());
+  };
 
+  TryAddImmediateValueFromNamedOperand(AMDGPU::OpName::src0_modifiers);
   Builder.add(*Src0);
 
-  if (AMDGPU::getNamedOperandIdx(NewOpcode, AMDGPU::OpName::src1_modifiers) !=
-      -1)
-    Builder.addImm(0);
-
+  TryAddImmediateValueFromNamedOperand(AMDGPU::OpName::src1_modifiers);
   Builder.add(*Src1);
 
-  if (AMDGPU::getNamedOperandIdx(NewOpcode, AMDGPU::OpName::clamp) != -1)
-    Builder.addImm(0);
+  TryAddImmediateValueFromNamedOperand(AMDGPU::OpName::clamp);
 
   return true;
 }

diff  --git a/llvm/test/CodeGen/AMDGPU/vcmp-saveexec-to-vcmpx.mir b/llvm/test/CodeGen/AMDGPU/vcmp-saveexec-to-vcmpx.mir
index 52cd6f5d47604..ecebd6f838bb0 100644
--- a/llvm/test/CodeGen/AMDGPU/vcmp-saveexec-to-vcmpx.mir
+++ b/llvm/test/CodeGen/AMDGPU/vcmp-saveexec-to-vcmpx.mir
@@ -1,5 +1,5 @@
-# RUN: llc -march=amdgcn -mcpu=gfx1010 -mattr=-wavefrontsize32,+wavefrontsize64 -run-pass=si-optimize-exec-masking -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s
-# RUN: llc -march=amdgcn -mcpu=gfx1030 -mattr=-wavefrontsize32,+wavefrontsize64 -run-pass=si-optimize-exec-masking -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s
+# RUN: llc -march=amdgcn -mcpu=gfx1010 -mattr=-wavefrontsize32,+wavefrontsize64 -run-pass=si-optimize-exec-masking -verify-machineinstrs %s -o - | FileCheck --check-prefixes=GCN,GFX1010 %s
+# RUN: llc -march=amdgcn -mcpu=gfx1030 -mattr=-wavefrontsize32,+wavefrontsize64 -run-pass=si-optimize-exec-masking -verify-machineinstrs %s -o - | FileCheck --check-prefixes=GCN,GFX1030 %s
 
 ---
 
@@ -22,3 +22,22 @@ body: |
     $sgpr2_sgpr3 = COPY $exec, implicit-def $exec
     $sgpr2_sgpr3 = S_AND_B64 killed renamable $sgpr2_sgpr3, killed renamable $sgpr0_sgpr1, implicit-def dead $scc
     $exec = S_MOV_B64_term killed renamable $sgpr2_sgpr3
+...
+
+---
+# Check if the modifiers are preserved when generating the V_CMPX instruction.
+
+# GCN-LABEL: name: vcmp_saveexec_to_mov_vcmpx_check_abs
+# GFX1010: V_CMP_LT_F32_e64
+# GFX1010: S_AND_SAVEEXEC_B64
+# GFX1030: S_MOV_B64
+# GFX1030-NEXT: V_CMPX_LT_F32_nosdst_e64 0, 953267991, 2
+name: vcmp_saveexec_to_mov_vcmpx_check_abs
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $vgpr0
+    renamable $sgpr0_sgpr1 = V_CMP_LT_F32_e64 0, 953267991, 2, $vgpr0, 0, implicit $mode, implicit $exec
+    $sgpr2_sgpr3 = COPY $exec, implicit-def $exec
+    $sgpr2_sgpr3 = S_AND_B64 killed renamable $sgpr2_sgpr3, killed renamable $sgpr0_sgpr1, implicit-def dead $scc
+    $exec = S_MOV_B64_term killed renamable $sgpr2_sgpr3


        


More information about the llvm-commits mailing list