mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-26 13:10:34 +00:00
LSR must sometimes sign-extend before generating double constants.
rdar://9786536 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135650 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fb4eb165d6
commit
c2c988e5e0
@ -1427,6 +1427,7 @@ void LSRInstance::OptimizeShadowIV() {
|
||||
++UI;
|
||||
Instruction *ShadowUse = CandidateUI->getUser();
|
||||
Type *DestTy = NULL;
|
||||
bool IsSigned = false;
|
||||
|
||||
/* If shadow use is a int->float cast then insert a second IV
|
||||
to eliminate this cast.
|
||||
@ -1440,10 +1441,14 @@ void LSRInstance::OptimizeShadowIV() {
|
||||
for (unsigned i = 0; i < n; ++i, ++d)
|
||||
foo(d);
|
||||
*/
|
||||
if (UIToFPInst *UCast = dyn_cast<UIToFPInst>(CandidateUI->getUser()))
|
||||
if (UIToFPInst *UCast = dyn_cast<UIToFPInst>(CandidateUI->getUser())) {
|
||||
IsSigned = false;
|
||||
DestTy = UCast->getDestTy();
|
||||
else if (SIToFPInst *SCast = dyn_cast<SIToFPInst>(CandidateUI->getUser()))
|
||||
}
|
||||
else if (SIToFPInst *SCast = dyn_cast<SIToFPInst>(CandidateUI->getUser())) {
|
||||
IsSigned = true;
|
||||
DestTy = SCast->getDestTy();
|
||||
}
|
||||
if (!DestTy) continue;
|
||||
|
||||
if (TLI) {
|
||||
@ -1474,7 +1479,9 @@ void LSRInstance::OptimizeShadowIV() {
|
||||
|
||||
ConstantInt *Init = dyn_cast<ConstantInt>(PH->getIncomingValue(Entry));
|
||||
if (!Init) continue;
|
||||
Constant *NewInit = ConstantFP::get(DestTy, Init->getZExtValue());
|
||||
Constant *NewInit = ConstantFP::get(DestTy, IsSigned ?
|
||||
Init->getSExtValue() :
|
||||
Init->getZExtValue());
|
||||
|
||||
BinaryOperator *Incr =
|
||||
dyn_cast<BinaryOperator>(PH->getIncomingValue(Latch));
|
||||
|
@ -15,7 +15,26 @@ entry:
|
||||
|
||||
loop:
|
||||
%i.01 = phi i32 [ -39, %entry ], [ %inc, %loop ]
|
||||
%conv7 = sitofp i32 %i.01 to double
|
||||
%conv = sitofp i32 %i.01 to double
|
||||
%inc = add nsw i32 %i.01, 1
|
||||
br i1 undef, label %loop, label %for.end
|
||||
|
||||
for.end:
|
||||
unreachable
|
||||
}
|
||||
|
||||
; Now check that the computed double constant is correct.
|
||||
; CHECK: @doubleIV
|
||||
; CHECK: phi double [ 0x43F0000000000000, %entry ]
|
||||
; CHECK: br
|
||||
define void @doubleIV() nounwind {
|
||||
entry:
|
||||
br label %loop
|
||||
|
||||
loop:
|
||||
%i.01 = phi i32 [ -39, %entry ], [ %inc, %loop ]
|
||||
%conv = sitofp i32 %i.01 to double
|
||||
%div = fdiv double %conv, 4.000000e+01
|
||||
%inc = add nsw i32 %i.01, 1
|
||||
br i1 undef, label %loop, label %for.end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user