diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1970,6 +1970,10 @@ if (!CI) continue; + // Apply nomerge attribute to all call sites inside inlined function. + if (CB.hasFnAttr(Attribute::NoMerge)) + CI->setCannotMerge(); + // Forward varargs from inlined call site to calls to the // ForwardVarArgsTo function, if requested, and to musttail calls. if (!VarArgsToForward.empty() && diff --git a/llvm/test/Transforms/Inline/inline_nomerge.ll b/llvm/test/Transforms/Inline/inline_nomerge.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/Inline/inline_nomerge.ll @@ -0,0 +1,37 @@ +; Check nomerge attribute at call sites applying to all call sites inside the inlined function. +; RUN: opt < %s -O3 -S | FileCheck %s + +declare void @f() +declare void @g() + +define void @bar() { +entry: + call void @f() + call void @g() + ret void +} + +define void @foo(i32 %i) { +entry: + switch i32 %i, label %if.end [ + i32 5, label %if.then + i32 7, label %if.then2 + ] + +if.then: + call void @bar() #0 ; CHECK: call void @f() #0 + ; CHECK-NEXT: call void @g() #0 + br label %if.end + +if.then2: + call void @bar() #0 ; CHECK: call void @f() #0 + ; CHECK-NEXT: call void @g() #0 + br label %if.end + +if.end: + call void @bar() #0 ; CHECK: call void @f() #0 + ; CHECK-NEXT: call void @g() #0 + ret void +} + +attributes #0 = { nomerge }