[llvm] r185299 - LoopVectorize: Math functions only read rounding mode

Arnold Schwaighofer aschwaighofer at apple.com
Mon Jul 1 07:46:11 PDT 2013


Hi Duncan,

“getIntrinsicIDForCall” is checking this constraint. It is a local function in LoopVectorize that will only return a non zero value for math functions:

static getIntrinsicIDForCall(CallInst *CI, const TargetLibraryInfo *TLI) {
  // If we have an intrinsic call, check if it is trivially vectorizable.
  if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI)) {
    switch (II->getIntrinsicID()) {
    case Intrinsic::sqrt:
    case Intrinsic::sin:
    case Intrinsic::cos:
    case Intrinsic::exp:
    case Intrinsic::exp2:
    case Intrinsic::log:
    case Intrinsic::log10:
    case Intrinsic::log2:
    case Intrinsic::fabs:
    case Intrinsic::floor:
    case Intrinsic::ceil:
    case Intrinsic::trunc:
    case Intrinsic::rint:
    case Intrinsic::nearbyint:
    case Intrinsic::pow:
    case Intrinsic::fma:
    case Intrinsic::fmuladd:
      return II->getIntrinsicID();
    default:
      return Intrinsic::not_intrinsic;
    }
  }
  LibFunc::Func Func;
  Function *F = CI->getCalledFunction();
  /// ... Do a similar check for LibFunc::Func functions.


On Jul 1, 2013, at 9:35 AM, Duncan Sands <duncan.sands at gmail.com> wrote:

> Hi Arnold,
> 
> On 01/07/13 02:54, Arnold Schwaighofer wrote:
>> Author: arnolds
>> Date: Sun Jun 30 19:54:44 2013
>> New Revision: 185299
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=185299&view=rev
>> Log:
>> LoopVectorize: Math functions only read rounding mode
>> 
>> Math functions are mark as readonly because they read the floating point
>> rounding mode. Because we don't vectorize loops that would contain function
>> calls that set the rounding mode it is safe to ignore this memory read.
> 
> how do you know that the intrinsic is a math intrinsic?  For example it could
> be an x86 unaligned load intrinsic, vector load intrinsic, or who knows what,
> that may be reading from some memory that is written to in the loop.
> 
> Ciao, Duncan.
> 
>> 
>> Added:
>>     llvm/trunk/test/Transforms/LoopVectorize/funcall.ll
>> Modified:
>>     llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
>> 
>> Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=185299&r1=185298&r2=185299&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Sun Jun 30 19:54:44 2013
>> @@ -3520,6 +3520,13 @@ bool LoopVectorizationLegality::canVecto
>>        // but is not a load, then we quit. Notice that we don't handle function
>>        // calls that read or write.
>>        if (it->mayReadFromMemory()) {
>> +        // Many math library functions read the rounding mode. We will only
>> +        // vectorize a loop if it contains known function calls that don't set
>> +        // the flag. Therefore, it is safe to ignore this read from memory.
>> +        CallInst *Call = dyn_cast<CallInst>(it);
>> +        if (Call && getIntrinsicIDForCall(Call, TLI))
>> +          continue;
>> +
>>          LoadInst *Ld = dyn_cast<LoadInst>(it);
>>          if (!Ld) return false;
>>          if (!Ld->isSimple() && !IsAnnotatedParallel) {





More information about the llvm-commits mailing list