Outliner: add "target-cpu" feature from source function to outlined
authorTim Northover <tnorthover@apple.com>
Fri, 29 Jul 2022 13:39:44 +0000 (14:39 +0100)
committerTim Northover <tnorthover@apple.com>
Tue, 2 Aug 2022 08:33:29 +0000 (09:33 +0100)
The CPU is used to determine which inline asm instructions are allowed, so
needs to be copied across in case the outlined function contains any.

llvm/lib/CodeGen/TargetInstrInfo.cpp
llvm/test/CodeGen/AArch64/machine-outliner.ll

index 4116231..0c0fdf7 100644 (file)
@@ -1411,6 +1411,8 @@ void TargetInstrInfo::mergeOutliningCandidateAttributes(
   const Function &ParentFn = FirstCand.getMF()->getFunction();
   if (ParentFn.hasFnAttribute("target-features"))
     F.addFnAttr(ParentFn.getFnAttribute("target-features"));
+  if (ParentFn.hasFnAttribute("target-cpu"))
+    F.addFnAttr(ParentFn.getFnAttribute("target-cpu"));
 
   // Set nounwind, so we don't generate eh_frame.
   if (llvm::all_of(Candidates, [](const outliner::Candidate &C) {
index 3d1c735..1ae905b 100644 (file)
@@ -11,6 +11,7 @@
 ; TARGET_FEATURES-SAME: minsize
 ; TARGET_FEATURES-SAME: nounwind
 ; TARGET_FEATURES-SAME: optsize
+; TARGET_FEATURES-SAME: "target-cpu"="cyclone"
 ; TARGET_FEATURES-SAME: "target-features"="+sse"
 
 define linkonce_odr void @fish() #0 {