• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -gvn -enable-load-pre -S | FileCheck %s
2; This testcase assumed we'll PRE the load into %for.cond, but we don't actually
3; verify that doing so is safe.  If there didn't _happen_ to be a load in
4; %for.end, we would actually be lengthening the execution on some paths, and
5; we were never actually checking that case.  Now we actually do perform some
6; conservative checking to make sure we don't make paths longer, but we don't
7; currently get this case, which we got lucky on previously.
8;
9; Now that that faulty assumption is corrected, test that we DON'T incorrectly
10; hoist the load.  Doing the right thing for the wrong reasons is still a bug.
11
12@p = external global i32
13define i32 @f(i32 %n) nounwind {
14entry:
15	br label %for.cond
16
17for.cond:		; preds = %for.inc, %entry
18	%i.0 = phi i32 [ 0, %entry ], [ %indvar.next, %for.inc ]		; <i32> [#uses=2]
19	%cmp = icmp slt i32 %i.0, %n		; <i1> [#uses=1]
20	br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
21
22for.cond.for.end_crit_edge:		; preds = %for.cond
23	br label %for.end
24
25; CHECK: for.body:
26; CHECK-NEXT: %tmp3 = load i32* @p
27for.body:		; preds = %for.cond
28	%tmp3 = load i32* @p		; <i32> [#uses=1]
29	%dec = add i32 %tmp3, -1		; <i32> [#uses=2]
30	store i32 %dec, i32* @p
31	%cmp6 = icmp slt i32 %dec, 0		; <i1> [#uses=1]
32	br i1 %cmp6, label %for.body.for.end_crit_edge, label %for.inc
33
34; CHECK: for.body.for.end_crit_edge:
35for.body.for.end_crit_edge:		; preds = %for.body
36	br label %for.end
37
38for.inc:		; preds = %for.body
39	%indvar.next = add i32 %i.0, 1		; <i32> [#uses=1]
40	br label %for.cond
41
42for.end:		; preds = %for.body.for.end_crit_edge, %for.cond.for.end_crit_edge
43	%tmp9 = load i32* @p		; <i32> [#uses=1]
44	ret i32 %tmp9
45}
46