[llvm-commits] [PATCH][FAST-MATH] recognize fp negation

Michael Ilseman milseman at apple.com
Fri Jan 4 11:52:27 PST 2013


On Jan 3, 2013, at 8:41 PM, Duncan Sands <baldrick at free.fr> wrote:

> Hi Shuxin,
> 
>>     Currently the compiler only considers "-0.0 - x" as a negation of quantity
>> x regardless the
>>  fast-math flags associated with the expr or the fast-math flags derived from
>> the supper-expr.
>>  This patch is to fix this problem.
>> 
>>    With this change, "0.0 - x" will be considered as negation of x as well so
>> long as we don't care
>> "signed-zero".
>> 
>>    It is about two weeks old. Unfortunately, as of I write this mail, I'm not
>> able to update the latest revision
>> and re-test it.
> 
> how about getting rid of isFNeg from InstrTypes, and move users over to the
> version in llvm/Support/PatternMatch.h instead?  I'm not sure it makes much
> sense to have these pattern matching predicates in InstrTypes.h any more -
> I suspect they are something of a historical relic nowadays.
> 
> Ciao, Duncan.
> 
> PS: Otherwise your patch looks fine, except for:
> 
>> --- lib/VMCore/Instructions.cpp	(revision 170838)
>> +++ lib/VMCore/Instructions.cpp	(working copy)
>> @@ -1928,11 +1928,11 @@
>>   return false;
>> }
>> 
>> -bool BinaryOperator::isFNeg(const Value *V) {
>> +bool BinaryOperator::isFNeg(const Value *V, bool IgnoreZeroSign) {
>>   if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
>>     if (Bop->getOpcode() == Instruction::FSub)
>>       if (Constant* C = dyn_cast<Constant>(Bop->getOperand(0)))
>> -        return C->isNegativeZeroValue();
>> +        return !IgnoreZeroSign ? C->isNegativeZeroValue() : C->isZeroValue();
> 
> If IgnoreZeroSign is true, don't you want to match both ordinary and negative
> zero?  Right now it only matches ordinary zero.

In this patch, isZeroValue() calls ConstantFP::isZero(). I believe that will return true for both positive and negative zero. This is because it calls APFloat which checks that the category is fcZero, but doesn't check the sign.



More information about the llvm-commits mailing list