diff options
| author | Jim Grosbach <grosbach@apple.com> | 2011-09-30 18:45:50 +0000 | 
|---|---|---|
| committer | Jim Grosbach <grosbach@apple.com> | 2011-09-30 18:45:50 +0000 | 
| commit | 24ff8346713d1ff9b5fbdf27dcc6e131846c68ed (patch) | |
| tree | 94cb8a7ce8b9813c953f44f5141789640332ad53 /llvm/lib/Transforms | |
| parent | e8e4dbf468f4745cff513776ce2c2b73d1fe0e89 (diff) | |
| download | bcm5719-llvm-24ff8346713d1ff9b5fbdf27dcc6e131846c68ed.tar.gz bcm5719-llvm-24ff8346713d1ff9b5fbdf27dcc6e131846c68ed.zip | |
float comparison to double 'zero' constant can just be a float 'zero.'
InstCombine was incorrectly considering the conversion of the constant
zero to be unsafe.
We want to transform:
define float @bar(float %x) nounwind readnone optsize ssp {
  %conv = fpext float %x to double
  %cmp = fcmp olt double %conv, 0.000000e+00
  %conv1 = zext i1 %cmp to i32
  %conv2 = sitofp i32 %conv1 to float
  ret float %conv2
}
Into:
define float @bar(float %x) nounwind readnone optsize ssp {
  %cmp = fcmp olt float %x, 0.000000e+00   ; <---- This
  %conv1 = zext i1 %cmp to i32
  %conv2 = sitofp i32 %conv1 to float
  ret float %conv2
}
rdar://10215914
llvm-svn: 140869
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 9 | 
1 files changed, 6 insertions, 3 deletions
| diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index d2faab52152..26432d2eed5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2837,10 +2837,13 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {          APFloat F = RHSF->getValueAPF();          F.convert(*Sem, APFloat::rmNearestTiesToEven, &Lossy); -        // Avoid lossy conversions and denormals. +        // Avoid lossy conversions and denormals. Zero is a special case +        // that's OK to convert. +        F.clearSign();          if (!Lossy && -            F.compare(APFloat::getSmallestNormalized(*Sem)) != -                                                           APFloat::cmpLessThan) +            ((F.compare(APFloat::getSmallestNormalized(*Sem)) != +                 APFloat::cmpLessThan) || F.isZero())) +            return new FCmpInst(I.getPredicate(), LHSExt->getOperand(0),                                ConstantFP::get(RHSC->getContext(), F));          break; | 

