diff options
author | Nadav Rotem <nrotem@apple.com> | 2013-09-21 00:27:05 +0000 |
---|---|---|
committer | Nadav Rotem <nrotem@apple.com> | 2013-09-21 00:27:05 +0000 |
commit | 2ecd8c90b037e58f4914acfc6a4ced5a01774a05 (patch) | |
tree | 626833dfa50687c04834178fa4da3948a7c62375 | |
parent | 74d3482f76d1f8a20cedfc6701e017e7fd337cf9 (diff) | |
download | external_llvm-2ecd8c90b037e58f4914acfc6a4ced5a01774a05.tar.gz external_llvm-2ecd8c90b037e58f4914acfc6a4ced5a01774a05.tar.bz2 external_llvm-2ecd8c90b037e58f4914acfc6a4ced5a01774a05.zip |
LoopVectorizer: Only allow vectorization of intrinsics. We can't know for sure that the functions 'abs' or 'round' are the functions from libm.
rdar://15012650
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191122 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Vectorize/LoopVectorize.cpp | 13 | ||||
-rw-r--r-- | test/Transforms/LoopVectorize/intrinsic.ll | 31 |
2 files changed, 39 insertions, 5 deletions
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 30908c8ebf..02029e6ae0 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2925,9 +2925,18 @@ bool LoopVectorizationLegality::canVectorizeInstrs() { // We still don't handle functions. However, we can ignore dbg intrinsic // calls and we do handle certain intrinsic and libm functions. CallInst *CI = dyn_cast<CallInst>(it); - if (CI && !getIntrinsicIDForCall(CI, TLI) && !isa<DbgInfoIntrinsic>(CI)) { + if (CI) { DEBUG(dbgs() << "LV: Found a call site.\n"); - return false; + + if (!isa<IntrinsicInst>(it)) { + DEBUG(dbgs() << "LV: We only vectorize intrinsics.\n"); + return false; + } + + if (!getIntrinsicIDForCall(CI, TLI) && !isa<DbgInfoIntrinsic>(CI)) { + DEBUG(dbgs() << "LV: Found an unknown intrinsic.\n"); + return false; + } } // Check that the instruction return type is vectorizable. diff --git a/test/Transforms/LoopVectorize/intrinsic.ll b/test/Transforms/LoopVectorize/intrinsic.ll index 216b937ad6..99d6646e67 100644 --- a/test/Transforms/LoopVectorize/intrinsic.ll +++ b/test/Transforms/LoopVectorize/intrinsic.ll @@ -1018,7 +1018,7 @@ for.body: ; preds = %entry, %for.body %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] %arrayidx = getelementptr inbounds float* %x, i64 %indvars.iv %0 = load float* %arrayidx, align 4 - %call = tail call float @fabsf(float %0) nounwind readnone + %call = tail call float @llvm.fabs.f32(float %0) nounwind readnone store float %call, float* %arrayidx, align 4 %indvars.iv.next = add i64 %indvars.iv, 1 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 @@ -1029,6 +1029,31 @@ for.end: ; preds = %for.body ret void } -declare float @fabsf(float) nounwind readnone - declare double @llvm.pow.f64(double, double) nounwind readnone + + +;CHECK: @not_intrin +;CHECK: @round +;CHECK-NOT: @round +;CHECK: ret +define void @not_intrin(i32* nocapture %A) nounwind ssp uwtable { + br label %1 + +; <label>:1 ; preds = %1, %0 + %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %1 ] + %2 = getelementptr inbounds i32* %A, i64 %indvars.iv + %3 = load i32* %2, align 4 + %4 = add nsw i32 %3, 3 + store i32 %4, i32* %2, align 4 + %5 = trunc i64 %indvars.iv to i32 + tail call void @round(i32 %5) nounwind + %indvars.iv.next = add i64 %indvars.iv, 1 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32 + %exitcond = icmp eq i32 %lftr.wideiv, 256 + br i1 %exitcond, label %6, label %1 + +; <label>:6 ; preds = %1 + ret void +} + +declare void @round(i32) |