[llvm-commits] [llvm] r51268 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/sitofp.ll
Chris Lattner
clattner at apple.com
Mon May 19 20:52:31 PDT 2008
On May 19, 2008, at 3:47 PM, Neil Booth wrote:
>> + // See if the FP constant is top large for the integer. For
>> example,
>
> Typo.
Fixed.
>> // Handle fcmp with constant RHS
>> if (Constant *RHSC = dyn_cast<Constant>(Op1)) {
>> + // If the constant is a nan, see if we can fold the comparison
>> based on it.
>> + if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHSC)) {
>> + if (CFP->getValueAPF().isNaN()) {
>> + if (FCmpInst::isOrdered(I.getPredicate())) // True if
>> ordered and...
>> + return ReplaceInstUsesWith(I,
>> ConstantInt::get(Type::Int1Ty, 0));
>> + if (FCmpInst::isUnordered(I.getPredicate())) // True if
>> unordered or...
>> + return ReplaceInstUsesWith(I,
>> ConstantInt::get(Type::Int1Ty, 1));
>> + if (FCmpInst::isUnordered(I.getPredicate())) // Undef on
>> unordered.
>> + return ReplaceInstUsesWith(I,
>> UndefValue::get(Type::Int1Ty));
>> +
>
> Duplicate test?
Fixed.
>> + // Okay, now we know that the FP constant fits in the range
>> [SMIN, SMAX] but
>> + // it may still be fractional. See if it is fractional by
>> casting the FP
>> + // value to the integer value and back, checking for equality.
>> Don't do this
>> + // for zero, because -0.0 is not fractional.
>
> Perhaps this is better done as an APFloat method if I understand what
> you're trying to do? It should be able to determine this reasonably
> easily without introducing allocations / conversions, though I've not
> thought about it a lot.
Yeah, I was meaning to ask you about this. What is the best way of
telling that an APFloat is fractional? I could do the conversion back
and forth and see if it is the same value, but that seems silly. Is
there a better way?
-Chris
More information about the llvm-commits
mailing list