[PowerPC] don't generate hardware loop.
authorChen Zheng <czhengsz@cn.ibm.com>
Mon, 19 Dec 2022 10:58:09 +0000 (05:58 -0500)
committerChen Zheng <czhengsz@cn.ibm.com>
Tue, 20 Dec 2022 01:32:29 +0000 (20:32 -0500)
If the candidate loop already has hardware loop related intrinsics,
don't generate hardware loop on PPC. PPC does not support nested
hardware loops.

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

index d834e34..5885c74 100644 (file)
@@ -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);
 
index 0d18b68..072cefa 100644 (file)
@@ -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 {