2010-09-25 13:26:18 +08:00
|
|
|
; RUN: opt < %s -gvn -enable-load-pre -S | FileCheck %s
|
|
|
|
; This testcase assumed we'll PRE the load into %for.cond, but we don't actually
|
|
|
|
; verify that doing so is safe. If there didn't _happen_ to be a load in
|
|
|
|
; %for.end, we would actually be lengthening the execution on some paths, and
|
|
|
|
; we were never actually checking that case. Now we actually do perform some
|
|
|
|
; conservative checking to make sure we don't make paths longer, but we don't
|
|
|
|
; currently get this case, which we got lucky on previously.
|
|
|
|
;
|
|
|
|
; Now that that faulty assumption is corrected, test that we DON'T incorrectly
|
|
|
|
; hoist the load. Doing the right thing for the wrong reasons is still a bug.
|
2009-05-31 17:03:40 +08:00
|
|
|
|
2009-06-18 04:48:23 +08:00
|
|
|
@p = external global i32
|
|
|
|
define i32 @f(i32 %n) nounwind {
|
2009-05-31 17:03:40 +08:00
|
|
|
entry:
|
|
|
|
br label %for.cond
|
|
|
|
|
|
|
|
for.cond: ; preds = %for.inc, %entry
|
|
|
|
%i.0 = phi i32 [ 0, %entry ], [ %indvar.next, %for.inc ] ; <i32> [#uses=2]
|
|
|
|
%cmp = icmp slt i32 %i.0, %n ; <i1> [#uses=1]
|
|
|
|
br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
|
|
|
|
|
|
|
|
for.cond.for.end_crit_edge: ; preds = %for.cond
|
|
|
|
br label %for.end
|
|
|
|
|
2010-09-25 13:26:18 +08:00
|
|
|
; CHECK: for.body:
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %tmp3 = load i32, i32* @p
|
2009-05-31 17:03:40 +08:00
|
|
|
for.body: ; preds = %for.cond
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp3 = load i32, i32* @p ; <i32> [#uses=1]
|
2009-05-31 17:03:40 +08:00
|
|
|
%dec = add i32 %tmp3, -1 ; <i32> [#uses=2]
|
2009-06-18 04:48:23 +08:00
|
|
|
store i32 %dec, i32* @p
|
2009-05-31 17:03:40 +08:00
|
|
|
%cmp6 = icmp slt i32 %dec, 0 ; <i1> [#uses=1]
|
|
|
|
br i1 %cmp6, label %for.body.for.end_crit_edge, label %for.inc
|
|
|
|
|
2010-09-25 13:26:18 +08:00
|
|
|
; CHECK: for.body.for.end_crit_edge:
|
2009-05-31 17:03:40 +08:00
|
|
|
for.body.for.end_crit_edge: ; preds = %for.body
|
|
|
|
br label %for.end
|
|
|
|
|
|
|
|
for.inc: ; preds = %for.body
|
|
|
|
%indvar.next = add i32 %i.0, 1 ; <i32> [#uses=1]
|
|
|
|
br label %for.cond
|
|
|
|
|
|
|
|
for.end: ; preds = %for.body.for.end_crit_edge, %for.cond.for.end_crit_edge
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp9 = load i32, i32* @p ; <i32> [#uses=1]
|
2009-05-31 17:03:40 +08:00
|
|
|
ret i32 %tmp9
|
|
|
|
}
|