[PATCH] D87180: [Inliner] Preserve maynotprogress function attribute

Atmn Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 4 22:12:16 PDT 2020


atmnpatel created this revision.
atmnpatel added reviewers: jdoerfert, hfinkel.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
atmnpatel requested review of this revision.

When inlining a function with the `maynotprogress` function attribute,
semantically, the caller function must also inherit the `maynotprogress`
attribute.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87180

Files:
  llvm/include/llvm/IR/Attributes.td
  llvm/test/Transforms/Inline/maynotprogress.ll


Index: llvm/test/Transforms/Inline/maynotprogress.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/maynotprogress.ll
@@ -0,0 +1,42 @@
+; RUN: opt -inline -S < %s | FileCheck %s
+
+;; Original C Code:
+;; void callee(int a, int b) {
+;;  for (;a < b;) ;
+;;  while(1) ;
+;; }
+;; void caller() {
+;;  callee(0, 5);
+;; }
+
+define void @callee(i32 %a, i32 %b) #0 {
+entry:
+  br label %for.cond
+for.cond:
+  %cmp = icmp slt i32 %a, %b
+  br i1 %cmp, label %for.body, label %for.end
+for.body:
+  br label %for.cond
+for.end:
+  br label %while.body
+while.body:
+  br label %while.body
+}
+
+; CHECK: define void @caller() [[ATTR0:#.*]] {
+; CHECK: entry:
+; CHECK:    br label %[[FOR_COND:.*]]
+; CHECK: [[FOR_COND]]:
+; CHECK:    br label %[[FOR_COND]]
+; CHECK:    ret void
+; CHECK: }
+
+define void @caller() {
+entry:
+  call void @callee(i32 0, i32 5)
+  ret void
+}
+
+; CHECK: attributes [[ATTR0]] = { maynotprogress }
+
+attributes #0 = { maynotprogress }
Index: llvm/include/llvm/IR/Attributes.td
===================================================================
--- llvm/include/llvm/IR/Attributes.td
+++ llvm/include/llvm/IR/Attributes.td
@@ -291,3 +291,4 @@
 def : MergeRule<"adjustCallerStackProbeSize">;
 def : MergeRule<"adjustMinLegalVectorWidth">;
 def : MergeRule<"adjustNullPointerValidAttr">;
+def : MergeRule<"setOR<MayNotProgressAttr>">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87180.290063.patch
Type: text/x-patch
Size: 1432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200905/10d8607a/attachment.bin>


More information about the llvm-commits mailing list