From 0b44f240331b47f3c0f2984ff0ad441ff1ab8414 Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Thu, 17 Mar 2016 17:11:33 +0000 Subject: [PATCH] [PowerPC] Disable CTR loops optimization for soft float operations This patch prevents CTR loops optimization when using soft float operations inside loop body. Soft float operations use function calls, but function calls are not allowed inside CTR optimized loops. Patch by Aleksandar Beserminji. Differential Revision: http://reviews.llvm.org/D17600 llvm-svn: 263727 --- llvm/lib/Target/PowerPC/PPCCTRLoops.cpp | 19 ++++ llvm/test/CodeGen/PowerPC/ctrloops-softfloat.ll | 129 ++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 llvm/test/CodeGen/PowerPC/ctrloops-softfloat.ll diff --git a/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp b/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp index b6ac4d5..b0a3e93 100644 --- a/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp +++ b/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp @@ -422,6 +422,25 @@ bool PPCCTRLoops::mightUseCTR(const Triple &TT, BasicBlock *BB) { if (SI->getNumCases() + 1 >= (unsigned)TLI->getMinimumJumpTableEntries()) return true; } + + if (TM->getSubtargetImpl(*BB->getParent())->getTargetLowering()->useSoftFloat()) { + switch(J->getOpcode()) { + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: + case Instruction::FRem: + case Instruction::FPTrunc: + case Instruction::FPExt: + case Instruction::FPToUI: + case Instruction::FPToSI: + case Instruction::UIToFP: + case Instruction::SIToFP: + case Instruction::FCmp: + return true; + } + } + for (Value *Operand : J->operands()) if (memAddrUsesCTR(TM, Operand)) return true; diff --git a/llvm/test/CodeGen/PowerPC/ctrloops-softfloat.ll b/llvm/test/CodeGen/PowerPC/ctrloops-softfloat.ll new file mode 100644 index 0000000..037bfda --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/ctrloops-softfloat.ll @@ -0,0 +1,129 @@ +; RUN: llc -mtriple=powerpc-unknown-linux-gnu -O1 < %s | FileCheck %s + +; double x, y; +; +; void foo1() +; { +; x = y = 1.1; +; for (int i = 0; i < 175; i++) +; y = x + y; +; } +; void foo2() +; { +; x = y = 1.1; +; for (int i = 0; i < 175; i++) +; y = x - y; +; } +; void foo3() +; { +; x = y = 1.1; +; for (int i = 0; i < 175; i++) +; y = x * y; +; } +; void foo4() +; { +; x = y = 1.1; +; for (int i = 0; i < 175; i++) +; y = x / y; +; } + +target datalayout = "E-m:e-p:32:32-i64:64-n32" +target triple = "powerpc-buildroot-linux-gnu" + +@y = common global double 0.000000e+00, align 8 +@x = common global double 0.000000e+00, align 8 + +define void @foo1() #0 { + store double 1.100000e+00, double* @y, align 8 + store double 1.100000e+00, double* @x, align 8 + br label %2 + +;