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