1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=early-cse -earlycse-debug-hash -S %s | FileCheck %s
4 %mystruct = type { i32 }
6 ; @var is global so that *every* GEP argument is Constant.
7 @var = external global %mystruct
9 ; Control flow is to make the dominance tree consider the final icmp before it
10 ; gets to simplify the purely constant one (%tst). Since that icmp uses the
11 ; select that gets considered next. Finally the select simplification looks at
12 ; the %tst icmp and we don't want it to speculate about what happens if "i32 0"
13 ; is actually "i32 1", broken universes are automatic UB.
15 ; In this case doing the speculation would create an invalid GEP(@var, 0, 1) and
18 define i1 @test_constant_speculation(i1 %c) {
19 ; CHECK-LABEL: @test_constant_speculation(
21 ; CHECK-NEXT: br i1 %c, label [[END:%.*]], label [[SELECT:%.*]]
23 ; CHECK-NEXT: br label [[END]]
25 ; CHECK-NEXT: [[TMP:%.*]] = phi ptr [ null, [[ENTRY:%.*]] ], [ @var, [[SELECT]] ]
26 ; CHECK-NEXT: [[RES:%.*]] = icmp eq ptr [[TMP]], null
27 ; CHECK-NEXT: ret i1 [[RES]]
30 br i1 %c, label %end, label %select
34 %tst = icmp eq i32 1, 0
35 %sel = select i1 %tst, ptr null, ptr @var
39 %tmp = phi ptr [null, %entry], [%sel, %select]
40 %res = icmp eq ptr %tmp, null