llvm.org GIT mirror llvm / eb6dd23
SCEV fix: Handle loop invariant loads. Fixes PR11882: NULL dereference in ComputeLoadConstantCompareExitLimit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153480 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
2 changed file(s) with 52 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
46184618 Indexes.push_back(0);
46194619 }
46204620
4621 // Loop-invariant loads may be a byproduct of loop optimization. Skip them.
4622 if (!VarIdx)
4623 return getCouldNotCompute();
4624
46214625 // Okay, we know we have a (load (gep GV, 0, X)) comparison with a constant.
46224626 // Check to see if X is a loop variant variable value now.
46234627 const SCEV *Idx = getSCEV(VarIdx);
68446848 return ProperlyDominatesBlock;
68456849 case scCouldNotCompute:
68466850 llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
6847 default:
6851 default:
68486852 llvm_unreachable("Unknown SCEV kind!");
68496853 }
68506854 }
0 ; RUN: opt < %s -basicaa -globalopt -instcombine -loop-rotate -licm -instcombine -indvars -loop-deletion -constmerge -S
1 ; PR11882: ComputeLoadConstantCompareExitLimit crash.
2 ;
3 ; for.body is deleted leaving a loop-invariant load.
4 ; CHECK-NOT: for.body
5 target datalayout = "e-p:64:64:64-n32:64"
6
7 @func_21_l_773 = external global i32, align 4
8 @g_814 = external global i32, align 4
9 @g_244 = internal global [1 x [0 x i32]] zeroinitializer, align 4
10
11 define void @func_21() nounwind uwtable ssp {
12 entry:
13 br label %lbl_818
14
15 lbl_818: ; preds = %for.end, %entry
16 call void (...)* @func_27()
17 store i32 0, i32* @g_814, align 4, !tbaa !0
18 br label %for.cond
19
20 for.cond: ; preds = %for.body, %lbl_818
21 %0 = load i32* @g_814, align 4, !tbaa !0
22 %cmp = icmp sle i32 %0, 0
23 br i1 %cmp, label %for.body, label %for.end
24
25 for.body: ; preds = %for.cond
26 %idxprom = sext i32 %0 to i64
27 %arrayidx = getelementptr inbounds [0 x i32]* getelementptr inbounds ([1 x [0 x i32]]* @g_244, i32 0, i64 0), i32 0, i64 %idxprom
28 %1 = load i32* %arrayidx, align 1, !tbaa !0
29 store i32 %1, i32* @func_21_l_773, align 4, !tbaa !0
30 store i32 1, i32* @g_814, align 4, !tbaa !0
31 br label %for.cond
32
33 for.end: ; preds = %for.cond
34 %2 = load i32* @func_21_l_773, align 4, !tbaa !0
35 %tobool = icmp ne i32 %2, 0
36 br i1 %tobool, label %lbl_818, label %if.end
37
38 if.end: ; preds = %for.end
39 ret void
40 }
41
42 declare void @func_27(...)
43
44 !0 = metadata !{metadata !"int", metadata !1}
45 !1 = metadata !{metadata !"omnipotent char", metadata !2}
46 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}