[PowerPC] Disable the CTR optimization in the presence of {min,max}num
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 26 Mar 2016 09:42:31 +0000 (09:42 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 26 Mar 2016 09:42:31 +0000 (09:42 +0000)
The minnum and maxnum intrinsics get lowered to libcalls which
invalidates the CTR optimization.

This fixes PR27083.

llvm-svn: 264508

llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
llvm/test/CodeGen/PowerPC/ctr-minmaxnum.ll [new file with mode: 0644]

index b0a3e93..2a1cb60 100644 (file)
@@ -291,6 +291,8 @@ bool PPCCTRLoops::mightUseCTR(const Triple &TT, BasicBlock *BB) {
           case Intrinsic::pow:
           case Intrinsic::sin:
           case Intrinsic::cos:
+          case Intrinsic::maxnum:
+          case Intrinsic::minnum:
             return true;
           case Intrinsic::copysign:
             if (CI->getArgOperand(0)->getType()->getScalarType()->
diff --git a/llvm/test/CodeGen/PowerPC/ctr-minmaxnum.ll b/llvm/test/CodeGen/PowerPC/ctr-minmaxnum.ll
new file mode 100644 (file)
index 0000000..c109b43
--- /dev/null
@@ -0,0 +1,44 @@
+; RUN: llc < %s | FileCheck %s
+target triple = "powerpc64le-unknown-linux-gnu"
+
+define void @test1(float %f, float* %fp) {
+entry:
+  br label %loop_body
+
+loop_body:
+  %invar_address.dim.0.01 = phi i64 [ 0, %entry ], [ %1, %loop_body ]
+  %0 = call float @llvm.minnum.f32(float %f, float 1.0)
+  store float %0, float* %fp, align 4
+  %1 = add i64 %invar_address.dim.0.01, 1
+  %2 = icmp eq i64 %1, 2
+  br i1 %2, label %loop_exit, label %loop_body
+
+loop_exit:
+  ret void
+}
+
+; CHECK-LABEL: test1:
+; CHECK: bl fminf
+
+
+define void @test2(float %f, float* %fp) {
+entry:
+  br label %loop_body
+
+loop_body:
+  %invar_address.dim.0.01 = phi i64 [ 0, %entry ], [ %1, %loop_body ]
+  %0 = call float @llvm.maxnum.f32(float %f, float 1.0)
+  store float %0, float* %fp, align 4
+  %1 = add i64 %invar_address.dim.0.01, 1
+  %2 = icmp eq i64 %1, 2
+  br i1 %2, label %loop_exit, label %loop_body
+
+loop_exit:
+  ret void
+}
+
+; CHECK-LABEL: test2:
+; CHECK: bl fmaxf
+
+declare float @llvm.minnum.f32(float, float)
+declare float @llvm.maxnum.f32(float, float)