From f74324a1f8a439e1b3c67b8db56a7b96fe4f91a7 Mon Sep 17 00:00:00 2001 From: Chen Zheng Date: Mon, 19 Dec 2022 05:58:09 -0500 Subject: [PATCH] [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. --- llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp | 8 ++++++++ llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp index d834e34..5885c74 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(&I)) + if (Call->getIntrinsicID() == Intrinsic::set_loop_iterations || + Call->getIntrinsicID() == Intrinsic::loop_decrement) + return false; + SmallVector ExitingBlocks; L->getExitingBlocks(ExitingBlocks); diff --git a/llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll b/llvm/test/CodeGen/PowerPC/ctrloop-intrin.ll index 0d18b68..072cefa 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 { -- 2.7.4