File tree Expand file tree Collapse file tree 2 files changed +36
-7
lines changed
test/Transforms/IndVarSimplify Expand file tree Collapse file tree 2 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -1944,13 +1944,15 @@ PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) {
1944
1944
// SCEVExpander. Henceforth, we produce 1-to-1 narrow to wide uses.
1945
1945
if (BasicBlock *LatchBlock = L->getLoopLatch ()) {
1946
1946
WideInc =
1947
- cast<Instruction>(WidePhi->getIncomingValueForBlock (LatchBlock));
1948
- WideIncExpr = SE->getSCEV (WideInc);
1949
- // Propagate the debug location associated with the original loop increment
1950
- // to the new (widened) increment.
1951
- auto *OrigInc =
1952
- cast<Instruction>(OrigPhi->getIncomingValueForBlock (LatchBlock));
1953
- WideInc->setDebugLoc (OrigInc->getDebugLoc ());
1947
+ dyn_cast<Instruction>(WidePhi->getIncomingValueForBlock (LatchBlock));
1948
+ if (WideInc) {
1949
+ WideIncExpr = SE->getSCEV (WideInc);
1950
+ // Propagate the debug location associated with the original loop
1951
+ // increment to the new (widened) increment.
1952
+ auto *OrigInc =
1953
+ cast<Instruction>(OrigPhi->getIncomingValueForBlock (LatchBlock));
1954
+ WideInc->setDebugLoc (OrigInc->getDebugLoc ());
1955
+ }
1954
1956
}
1955
1957
1956
1958
LLVM_DEBUG (dbgs () << " Wide IV: " << *WidePhi << " \n " );
Original file line number Diff line number Diff line change
1
+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2
+ ; RUN: opt -S -passes=indvars < %s | FileCheck %s
3
+
4
+ target datalayout = "n8:16:32:64"
5
+
6
+ ; Just make sure this doesn't crash.
7
+ ; SCEVExpander produces a degenerate phi node for the widened IV here,
8
+ ; where the "increment" instruction folds to a poison value.
9
+ define i32 @main () {
10
+ ; CHECK-LABEL: define i32 @main() {
11
+ ; CHECK-NEXT: entry:
12
+ ; CHECK-NEXT: br label [[LOOP:%.*]]
13
+ ; CHECK: loop:
14
+ ; CHECK-NEXT: br label [[LOOP]]
15
+ ;
16
+ entry:
17
+ %div = sdiv i32 1 , 0
18
+ %trunc = trunc i32 %div to i16
19
+ br label %loop
20
+
21
+ loop:
22
+ %phi = phi i16 [ 0 , %entry ], [ %or , %loop ]
23
+ %or = or i16 %phi , %trunc
24
+ %phi.ext = sext i16 %phi to i64
25
+ %add.ptr = getelementptr i8 , ptr null , i64 %phi.ext
26
+ br label %loop
27
+ }
You can’t perform that action at this time.
0 commit comments