[llvm] f74324a - [PowerPC] don't generate hardware loop.

Chen Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 17:36:58 PST 2022


Author: Chen Zheng
Date: 2022-12-19T20:32:29-05:00
New Revision: f74324a1f8a439e1b3c67b8db56a7b96fe4f91a7

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

LOG: [PowerPC] don't generate hardware loop.

If the candidate loop already has hardware loop related intrinsics,
don't generate hardware loop on PPC. PPC does not support nested
hardware loops.

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
    llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
index d834e346dcff0..5885c74e91daa 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
@@ -383,6 +383,14 @@ bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
       return false;
   }
 
+  // Check that there is no hardware loop related intrinsics in the loop.
+  for (auto *BB : L->getBlocks())
+    for (auto &I : *BB)
+      if (auto *Call = dyn_cast<IntrinsicInst>(&I))
+        if (Call->getIntrinsicID() == Intrinsic::set_loop_iterations ||
+            Call->getIntrinsicID() == Intrinsic::loop_decrement)
+          return false;
+
   SmallVector<BasicBlock*, 4> ExitingBlocks;
   L->getExitingBlocks(ExitingBlocks);
 

diff  --git a/llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll b/llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll
index 0d18b68ad2609..072cefa82fa5d 100644
--- a/llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll
+++ b/llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll
@@ -28,10 +28,10 @@ declare ptr @halide_string_to_string(ptr, ptr, ptr) #1
 ; Function Attrs: nounwind
 declare ptr @halide_int64_to_string(ptr, ptr, i64, i32) #1
 
-;; FIXME: hardware loop should not be generated in the loop that already has a
-;; user defined hardware loop. Only one mtctr should be in the final assembly.
+;; Hardware loop should not be generated in the loop that already has a user
+;; defined hardware loop. Only one mtctr should be in the final assembly.
 ; CHECK-LABEL: halide_double_to_string
-; CHECK-COUNT-2: mtctr
+; CHECK-COUNT-1: mtctr
 
 ; Function Attrs: nounwind
 define weak ptr @halide_double_to_string(ptr %dst, ptr %end, double %arg, i32 %scientific) #1 {


        


More information about the llvm-commits mailing list