Skip to content

Commit 2230404

Browse files
author
Hal Finkel
committed
Account for 128-bit integer operations in PPCCTRLoops
We need to abort the formation of counter-register-based loops where there are 128-bit integer operations that might become function calls. llvm-svn: 202192
1 parent 449d3b7 commit 2230404

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

llvm/lib/Target/PowerPC/PPCCTRLoops.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ bool PPCCTRLoops::runOnFunction(Function &F) {
187187
return MadeChange;
188188
}
189189

190+
static bool isLargeIntegerTy(bool Is32Bit, Type *Ty) {
191+
if (IntegerType *ITy = dyn_cast<IntegerType>(Ty))
192+
return ITy->getBitWidth() > (Is32Bit ? 32 : 64);
193+
194+
return false;
195+
}
196+
190197
bool PPCCTRLoops::mightUseCTR(const Triple &TT, BasicBlock *BB) {
191198
for (BasicBlock::iterator J = BB->begin(), JE = BB->end();
192199
J != JE; ++J) {
@@ -353,13 +360,11 @@ bool PPCCTRLoops::mightUseCTR(const Triple &TT, BasicBlock *BB) {
353360
CastInst *CI = cast<CastInst>(J);
354361
if (CI->getSrcTy()->getScalarType()->isPPC_FP128Ty() ||
355362
CI->getDestTy()->getScalarType()->isPPC_FP128Ty() ||
356-
(TT.isArch32Bit() &&
357-
(CI->getSrcTy()->getScalarType()->isIntegerTy(64) ||
358-
CI->getDestTy()->getScalarType()->isIntegerTy(64))
359-
))
363+
isLargeIntegerTy(TT.isArch32Bit(), CI->getSrcTy()->getScalarType()) ||
364+
isLargeIntegerTy(TT.isArch32Bit(), CI->getDestTy()->getScalarType()))
360365
return true;
361-
} else if (TT.isArch32Bit() &&
362-
J->getType()->getScalarType()->isIntegerTy(64) &&
366+
} else if (isLargeIntegerTy(TT.isArch32Bit(),
367+
J->getType()->getScalarType()) &&
363368
(J->getOpcode() == Instruction::UDiv ||
364369
J->getOpcode() == Instruction::SDiv ||
365370
J->getOpcode() == Instruction::URem ||
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc < %s -march=ppc64 | FileCheck %s
2+
target datalayout = "E-m:e-i64:64-n32:64"
3+
target triple = "powerpc64-unknown-linux-gnu"
4+
5+
; Function Attrs: nounwind
6+
define hidden void @_mpd_shortdiv(i64 %n) #0 {
7+
entry:
8+
br i1 undef, label %for.end, label %for.body.lr.ph
9+
10+
for.body.lr.ph: ; preds = %entry
11+
br label %for.body
12+
13+
for.body: ; preds = %for.body, %for.body.lr.ph
14+
%i.018.in = phi i64 [ %n, %for.body.lr.ph ], [ %i.018, %for.body ]
15+
%i.018 = add i64 %i.018.in, -1
16+
%add.i = or i128 undef, undef
17+
%div.i = udiv i128 %add.i, 0
18+
%conv3.i11 = trunc i128 %div.i to i64
19+
store i64 %conv3.i11, i64* undef, align 8
20+
%cmp = icmp eq i64 %i.018, 0
21+
br i1 %cmp, label %for.end, label %for.body
22+
23+
for.end: ; preds = %for.body, %entry
24+
ret void
25+
}
26+
27+
; CHECK-LABEL: @_mpd_shortdiv
28+
; CHECK-NOT: mtctr
29+
30+
attributes #0 = { nounwind }
31+

0 commit comments

Comments
 (0)