[llvm] cf42610 - [SystemZ] Improve emission of alignment hints.

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 10:32:59 PST 2022


Author: Jonas Paulsson
Date: 2022-02-17T12:30:43-06:00
New Revision: cf426100d665e8368abfc036a734b2402f94fac0

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

LOG: [SystemZ] Improve emission of alignment hints.

Handle multiple memoperands in lowerAlignmentHint().

Review: Ulrich Weigand

Added: 
    

Modified: 
    llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
    llvm/test/CodeGen/SystemZ/vec-move-03.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 5c255967bc870..46538f966cd90 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -88,13 +88,19 @@ static const MCSymbolRefExpr *getGlobalOffsetTable(MCContext &Context) {
 // an instruction with the corresponding hint set.
 static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI,
                                unsigned Opcode) {
-  if (!MI->hasOneMemOperand())
+  if (MI->memoperands_empty())
     return;
-  const MachineMemOperand *MMO = *MI->memoperands_begin();
+
+  Align Alignment = Align(16);
+  for (MachineInstr::mmo_iterator MMOI = MI->memoperands_begin(),
+         EE = MI->memoperands_end(); MMOI != EE; ++MMOI)
+    if ((*MMOI)->getAlign() < Alignment)
+      Alignment = (*MMOI)->getAlign();
+
   unsigned AlignmentHint = 0;
-  if (MMO->getAlign() >= Align(16))
+  if (Alignment >= Align(16))
     AlignmentHint = 4;
-  else if (MMO->getAlign() >= Align(8))
+  else if (Alignment >= Align(8))
     AlignmentHint = 3;
   if (AlignmentHint == 0)
     return;

diff  --git a/llvm/test/CodeGen/SystemZ/vec-move-03.ll b/llvm/test/CodeGen/SystemZ/vec-move-03.ll
index 4f5bb0c374f4a..6e5b314d75618 100644
--- a/llvm/test/CodeGen/SystemZ/vec-move-03.ll
+++ b/llvm/test/CodeGen/SystemZ/vec-move-03.ll
@@ -182,3 +182,35 @@ define void @f19(<16 x i8> %val, <16 x i8> *%ptr) {
   ret void
 }
 
+; Test that the alignment hint for VST is emitted also when CFG optimizer
+; replaces two VSTs with just one that then carries two memoperands.
+define void @f20() {
+; CHECK-LABEL: f20:
+; CHECK: vst %v0, 0(%r1), 3
+; CHECK-NOT: vst
+entry:
+  switch i32 undef, label %exit [
+    i32 1, label %bb1
+    i32 2, label %bb2
+  ]
+
+bb1:
+  %C1 = call i64* @foo()
+  %I1 = insertelement <2 x i64*> poison, i64* %C1, i64 0
+  %S1 = shufflevector <2 x i64*> %I1, <2 x i64*> poison, <2 x i32> zeroinitializer
+  store <2 x i64*> %S1, <2 x i64*>* undef, align 8
+  br label %exit
+
+bb2:
+  %C2 = call i64* @foo()
+  %I2 = insertelement <2 x i64*> poison, i64* %C2, i64 0
+  %S2 = shufflevector <2 x i64*> %I2, <2 x i64*> poison, <2 x i32> zeroinitializer
+  %U = bitcast i64** undef to <2 x i64*>*
+  store <2 x i64*> %S2, <2 x i64*>* %U, align 8
+  br label %exit
+
+exit:
+  ret void
+}
+
+declare i64* @foo()


        


More information about the llvm-commits mailing list