1 ; RUN: opt -early-cse -S %s | FileCheck %s 2 3 %mystruct = type { i32 } 4 5 ; @var is global so that *every* GEP argument is Constant. 6 @var = external global %mystruct 7 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. 13 ; 14 ; In this case doing the speculation would create an invalid GEP(@var, 0, 1) and 15 ; crash. 16 17 define i1 @test_constant_speculation() { 18 ; CHECK-LABEL: define i1 @test_constant_speculation 19 entry: 20 br i1 undef, label %end, label %select 21 22 select: 23 ; CHECK: select: 24 ; CHECK-NOT: icmp 25 ; CHECK-NOT: getelementptr 26 ; CHECK-NOT: select 27 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 31 br label %end 32 33 end: 34 ; CHECK: end: 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 38 ret i1 %res 39 } 40