llvm.org GIT mirror llvm / 1419ad7
Merging r183035: ------------------------------------------------------------------------ r183035 | arnolds | 2013-05-31 12:53:50 -0700 (Fri, 31 May 2013) | 7 lines LoopVectorize: PHIs with only outside users should prevent vectorization We check that instructions in the loop don't have outside users (except if they are reduction values). Unfortunately, we skipped this check for if-convertable PHIs. Fixes PR16184. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_33@183189 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
2 changed file(s) with 71 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
23772377 return true;
23782378 }
23792379
2380 /// \brief Check that the instruction has outside loop users and is not an
2381 /// identified reduction variable.
2382 static bool hasOutsideLoopUser(const Loop *TheLoop, Instruction *Inst,
2383 SmallPtrSet &Reductions) {
2384 // Reduction instructions are allowed to have exit users. All other
2385 // instructions must not have external users.
2386 if (!Reductions.count(Inst))
2387 //Check that all of the users of the loop are inside the BB.
2388 for (Value::use_iterator I = Inst->use_begin(), E = Inst->use_end();
2389 I != E; ++I) {
2390 Instruction *U = cast(*I);
2391 // This user may be a reduction exit value.
2392 if (!TheLoop->contains(U)) {
2393 DEBUG(dbgs() << "LV: Found an outside user for : "<< *U << "\n");
2394 return true;
2395 }
2396 }
2397 return false;
2398 }
2399
23802400 bool LoopVectorizationLegality::canVectorizeInstrs() {
23812401 BasicBlock *PreHeader = TheLoop->getLoopPreheader();
23822402 BasicBlock *Header = TheLoop->getHeader();
24152435 // If this PHINode is not in the header block, then we know that we
24162436 // can convert it to select during if-conversion. No need to check if
24172437 // the PHIs in this block are induction or reduction variables.
2418 if (*bb != Header)
2419 continue;
2438 if (*bb != Header) {
2439 // Check that this instruction has no outside users or is an
2440 // identified reduction value with an outside user.
2441 if(!hasOutsideLoopUser(TheLoop, it, AllowedExit))
2442 continue;
2443 return false;
2444 }
24202445
24212446 // We only allow if-converted PHIs with more than two incoming values.
24222447 if (Phi->getNumIncomingValues() != 2) {
25092534
25102535 // Reduction instructions are allowed to have exit users.
25112536 // All other instructions must not have external users.
2512 if (!AllowedExit.count(it))
2513 //Check that all of the users of the loop are inside the BB.
2514 for (Value::use_iterator I = it->use_begin(), E = it->use_end();
2515 I != E; ++I) {
2516 Instruction *U = cast(*I);
2517 // This user may be a reduction exit value.
2518 if (!TheLoop->contains(U)) {
2519 DEBUG(dbgs() << "LV: Found an outside user for : "<< *U << "\n");
2520 return false;
2521 }
2522 }
2537 if (hasOutsideLoopUser(TheLoop, it, AllowedExit))
2538 return false;
2539
25232540 } // next instr.
25242541
25252542 }
0 ; RUN: opt -S -loop-vectorize -force-vector-unroll=1 -force-vector-width=2 < %s | FileCheck %s
1
2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
3
4 @f = common global i32 0, align 4
5 @.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
6 @c = common global i32 0, align 4
7 @a = common global i32 0, align 4
8 @b = common global i32 0, align 4
9 @e = common global i32 0, align 4
10
11 ; We used to vectorize this loop. But it has a value that is used outside of the
12 ; and is not a recognized reduction variable "tmp17".
13
14 ; CHECK-NOT: <2 x i32>
15
16 define i32 @main() {
17 bb:
18 %b.promoted = load i32* @b, align 4
19 br label %.lr.ph.i
20
21 .lr.ph.i:
22 %tmp8 = phi i32 [ %tmp18, %bb16 ], [ %b.promoted, %bb ]
23 %tmp2 = icmp sgt i32 %tmp8, 10
24 br i1 %tmp2, label %bb16, label %bb10
25
26 bb10:
27 br label %bb16
28
29 bb16:
30 %tmp17 = phi i32 [ 0, %bb10 ], [ 1, %.lr.ph.i ]
31 %tmp18 = add nsw i32 %tmp8, 1
32 %tmp19 = icmp slt i32 %tmp18, 4
33 br i1 %tmp19, label %.lr.ph.i, label %f1.exit.loopexit
34
35 f1.exit.loopexit:
36 %.lcssa = phi i32 [ %tmp17, %bb16 ]
37 ret i32 %.lcssa
38 }
39
40