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