[PATCH] D137888: [LoongArch] Transfer MI flags when expand PseudoCALL

wanglei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 12 01:37:58 PST 2022


wangleiat created this revision.
wangleiat added reviewers: SixWeining, xen0n, xry111, gonglingqin, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
wangleiat requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When expanding a PseudoCALL, the corresponding flags (e.g. nomerge)
need to be passed to the new instruction.

This patch also adds test for the nomerge attribute.

The `nomerge` attribute was added during `LowerCall`, but was lost
during expand PseudoCALL. Now add it back.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137888

Files:
  llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
  llvm/test/CodeGen/LoongArch/nomerge.ll


Index: llvm/test/CodeGen/LoongArch/nomerge.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/nomerge.ll
@@ -0,0 +1,35 @@
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+define void @foo(i32 %i) {
+entry:
+  switch i32 %i, label %if.end3 [
+    i32 5, label %if.then
+    i32 7, label %if.then2
+  ]
+
+if.then:
+  tail call void @bar() #0
+  br label %if.end3
+
+if.then2:
+  tail call void @bar() #0
+  br label %if.end3
+
+if.end3:
+  tail call void @bar() #0
+  ret void
+}
+
+declare void @bar()
+
+attributes #0 = { nomerge }
+
+; CHECK-LABEL: foo:
+; CHECK: # %bb.0: # %entry
+; CHECK: # %bb.1: # %entry
+; CHECK: # %bb.2: # %if.then
+; CHECK-NEXT: bl %plt(bar)
+; CHECK: .LBB0_3: # %if.then2
+; CHECK-NEXT: bl %plt(bar)
+; CHECK: .LBB0_4: # %if.end3
+; CHECK: bl %plt(bar)
Index: llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
+++ llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
@@ -285,6 +285,9 @@
   // Transfer implicit operands.
   CALL.copyImplicitOps(MI);
 
+  // Transfer MI flags.
+  CALL.setMIFlags(MI.getFlags());
+
   MI.eraseFromParent();
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137888.474933.patch
Type: text/x-patch
Size: 1301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221112/44f9edd2/attachment.bin>


More information about the llvm-commits mailing list