1 ; RUN: opt -early-cse -S %s | FileCheck %s
3 %mystruct = type { i32 }
5 ; @var is global so that *every* GEP argument is Constant.
6 @var = external global %mystruct
8 ; Control flow is to make the dominance tree consider the final icmp before it
9 ; gets to simplify the purely constant one (%tst). Since that icmp uses the
10 ; select that gets considered next. Finally the select simplification looks at
11 ; the %tst icmp and we don't want it to speculate about what happens if "i32 0"
12 ; is actually "i32 1", broken universes are automatic UB.
14 ; In this case doing the speculation would create an invalid GEP(@var, 0, 1) and
17 define i1 @test_constant_speculation() {
18 ; CHECK-LABEL: define i1 @test_constant_speculation
20 br i1 undef, label %end, label %select
25 ; CHECK-NOT: getelementptr
28 %tst = icmp eq i32 1, 0
29 %elt = getelementptr %mystruct, %mystruct* @var, i64 0, i32 0
30 %sel = select i1 %tst, i32* null, i32* %elt
35 ; CHECK: %tmp = phi i32* [ null, %entry ], [ getelementptr inbounds (%mystruct, %mystruct* @var, i64 0, i32 0), %select ]
36 %tmp = phi i32* [null, %entry], [%sel, %select]
37 %res = icmp eq i32* %tmp, null