llvm.org GIT mirror llvm / 011536a
[SCEV] Fix PR22856. Summary: ScalarEvolutionExpander assumes that the header block of a loop is a legal place to have a use for a phi node. This is true only for phis that are either in the header or dominate the header block, but it is not true for phi nodes that are strictly internal to the loop body. This change teaches ScalarEvolutionExpander to place uses of PHI nodes in the basic block the PHI nodes belong to. This is always legal, and `hoistIVInc` ensures that the said position dominates `IsomorphicInc`. Reviewers: atrick Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8311 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232189 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 5 years ago
2 changed file(s) with 39 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
17701770 << *IsomorphicInc << '\n');
17711771 Value *NewInc = OrigInc;
17721772 if (OrigInc->getType() != IsomorphicInc->getType()) {
1773 Instruction *IP = isa(OrigInc)
1774 ? (Instruction*)L->getHeader()->getFirstInsertionPt()
1775 : OrigInc->getNextNode();
1773 Instruction *IP = nullptr;
1774 if (PHINode *PN = dyn_cast(OrigInc))
1775 IP = PN->getParent()->getFirstInsertionPt();
1776 else
1777 IP = OrigInc->getNextNode();
1778
17761779 IRBuilder<> Builder(IP);
17771780 Builder.SetCurrentDebugLocation(IsomorphicInc->getDebugLoc());
17781781 NewInc = Builder.
0 ; RUN: opt -loop-reduce -verify < %s
1
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64--linux-gnu"
4
5 define void @unbounded() {
6
7 block_A:
8 %0 = sext i32 undef to i64
9 br i1 undef, label %block_F, label %block_G
10
11 block_C: ; preds = %block_F
12 br i1 undef, label %block_D, label %block_E
13
14 block_D: ; preds = %block_D, %block_C
15 br i1 undef, label %block_E, label %block_D
16
17 block_E: ; preds = %block_D, %block_C
18 %iv2 = phi i64 [ %4, %block_D ], [ %4, %block_C ]
19 %1 = add nsw i32 %iv1, 1
20 %2 = icmp eq i32 %1, undef
21 br i1 %2, label %block_G, label %block_F
22
23 block_F: ; preds = %block_E, %block_A
24 %iv3 = phi i64 [ %iv2, %block_E ], [ %0, %block_A ]
25 %iv1 = phi i32 [ %1, %block_E ], [ undef, %block_A ]
26 %3 = add nsw i64 %iv3, 2
27 %4 = add nsw i64 %iv3, 1
28 br label %block_C
29
30 block_G: ; preds = %block_E, %block_A
31 ret void
32 }