[llvm-commits] [llvm] r168648 - in /llvm/trunk: include/llvm/Analysis/InstructionSimplify.h lib/Analysis/InstructionSimplify.cpp

Michael Ilseman milseman at apple.com
Mon Nov 26 16:58:51 PST 2012


On Nov 26, 2012, at 4:55 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Mon, Nov 26, 2012 at 4:46 PM, Michael Ilseman <milseman at apple.com> wrote:
>> Author: milseman
>> Date: Mon Nov 26 18:46:26 2012
>> New Revision: 168648
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=168648&view=rev
>> Log:
>> Fast-math optimization: fold multiply by zero
>> 
>> Added in first optimization using fast-math flags to serve as an example for following optimizations. SimplifyInstruction will now try to optimize an fmul observing its FastMathFlags to see if it can fold multiply by zero when 'nnan' and 'nsz' flags are set.
>> 
>> 
>> Modified:
>>    llvm/trunk/include/llvm/Analysis/InstructionSimplify.h
>>    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
>> 
>> Modified: llvm/trunk/include/llvm/Analysis/InstructionSimplify.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InstructionSimplify.h?rev=168648&r1=168647&r2=168648&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Analysis/InstructionSimplify.h (original)
>> +++ llvm/trunk/include/llvm/Analysis/InstructionSimplify.h Mon Nov 26 18:46:26 2012
>> @@ -25,6 +25,7 @@
>>   class DominatorTree;
>>   class Instruction;
>>   class DataLayout;
>> +  struct FastMathFlags;
>>   class TargetLibraryInfo;
>>   class Type;
>>   class Value;
>> @@ -43,6 +44,14 @@
>>                          const TargetLibraryInfo *TLI = 0,
>>                          const DominatorTree *DT = 0);
>> 
>> +  /// Given operands for an FMul, see if we can fold the result.  If not, this
>> +  /// returns null.
>> +  Value *SimplifyFMulInst(Value *LHS, Value *RHS,
>> +                          FastMathFlags FMF,
>> +                          const DataLayout *TD = 0,
>> +                          const TargetLibraryInfo *TLI = 0,
>> +                          const DominatorTree *DT = 0);
>> +
>>   /// SimplifyMulInst - Given operands for a Mul, see if we can
>>   /// fold the result.  If not, this returns null.
>>   Value *SimplifyMulInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
>> 
>> Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=168648&r1=168647&r2=168648&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
>> +++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Nov 26 18:46:26 2012
>> @@ -886,6 +886,33 @@
>>                            RecursionLimit);
>> }
>> 
>> +/// Given the operands for an FMul, see if we can fold the result
>> +static Value *SimplifyFMulInst(Value *Op0, Value *Op1,
>> +                               FastMathFlags FMF,
>> +                               const Query &Q,
>> +                               unsigned MaxRecurse) {
>> + if (Constant *CLHS = dyn_cast<Constant>(Op0)) {
>> +    if (Constant *CRHS = dyn_cast<Constant>(Op1)) {
>> +      Constant *Ops[] = { CLHS, CRHS };
>> +      return ConstantFoldInstOperands(Instruction::FMul, CLHS->getType(),
>> +                                      Ops, Q.TD, Q.TLI);
>> +    }
>> + }
>> +
>> + // Check for some fast-math optimizations
>> + if (FMF.NoNaNs) {
>> +   if (FMF.NoSignedZeros) {
> 
> You can write this as "FMF.NoNaNs && FMF.NoSignedZeros".
> 

I plan on adding in more optimizations that apply with just NoNaNs and don't need NoSignedZeros.

> -Eli




More information about the llvm-commits mailing list