Skip to content

Commit

Permalink
SLPVectorizer: Don't vectorize phi nodes that use invoke values
Browse files Browse the repository at this point in the history
We can't insert an insertelement after an invoke. We would have to split a
critical edge. So when we see a phi node that uses an invoke we just give up.

radar://14990770

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190871 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
aschwaighofer committed Sep 17, 2013
1 parent 0119f3d commit 3c94006
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) {
switch (Opcode) {
case Instruction::PHI: {
PHINode *PH = dyn_cast<PHINode>(VL0);

// Check for terminator values (e.g. invoke).
for (unsigned j = 0; j < VL.size(); ++j)
for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) {
TerminatorInst *Term = dyn_cast<TerminatorInst>(cast<PHINode>(VL[j])->getIncomingValue(i));
if (Term) {
DEBUG(dbgs() << "SLP: Need to swizzle PHINodes (TerminatorInst use).\n");
newTreeEntry(VL, false);
return;
}
}

newTreeEntry(VL, true);
DEBUG(dbgs() << "SLP: added a vector of PHINodes.\n");

Expand Down
62 changes: 62 additions & 0 deletions test/Transforms/SLPVectorizer/X86/ordering.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,65 @@ entry:
%cmp11 = fcmp olt double %add, 0.000000e+00
ret void
}

declare i8* @objc_msgSend(i8*, i8*, ...)
declare i32 @personality_v0(...)

define void @invoketest() {
entry:
br i1 undef, label %cond.true, label %cond.false

cond.true:
%call49 = invoke double bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to double (i8*, i8*)*)(i8* undef, i8* undef)
to label %cond.true54 unwind label %lpad

cond.false:
%call51 = invoke double bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to double (i8*, i8*)*)(i8* undef, i8* undef)
to label %cond.false57 unwind label %lpad

cond.true54:
%call56 = invoke double bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to double (i8*, i8*)*)(i8* undef, i8* undef)
to label %cond.end60 unwind label %lpad

cond.false57:
%call59 = invoke double bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to double (i8*, i8*)*)(i8* undef, i8* undef)
to label %cond.end60 unwind label %lpad

; Make sure we don't vectorize these phis - they have invokes as inputs.

; RUN: opt < %s -slp-vectorizer -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7 | FileCheck %s

; CHECK-LABEL: invoketest

; CHECK-LABEL: cond.end60
; CHECK-NEXT-NOT: phi <2 x double>
; CHECK: insertelement
; CHECK-LABEL: if.then63

cond.end60:
%cond126 = phi double [ %call49, %cond.true54 ], [ %call51, %cond.false57 ]
%cond61 = phi double [ %call56, %cond.true54 ], [ %call59, %cond.false57 ]
br i1 undef, label %if.end98, label %if.then63

if.then63:
%conv69 = fptrunc double undef to float
%conv70 = fpext float %conv69 to double
%div71 = fdiv double %cond126, %conv70
%conv78 = fptrunc double undef to float
%conv79 = fpext float %conv78 to double
%div80 = fdiv double %cond61, %conv79
br label %if.end98

lpad:
%l = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @personality_v0 to i8*)
cleanup
resume { i8*, i32 } %l

if.end98:
%dimensionsResult.sroa.0.0 = phi double [ %div71, %if.then63 ], [ %cond126, %cond.end60 ]
%dimensionsResult.sroa.6.0 = phi double [ %div80, %if.then63 ], [ %cond61, %cond.end60 ]
br label %if.end99

if.end99:
ret void
}

0 comments on commit 3c94006

Please sign in to comment.