1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -early-cse -earlycse-debug-hash -S %s | FileCheck %s 3 4%mystruct = type { i32 } 5 6; @var is global so that *every* GEP argument is Constant. 7@var = external global %mystruct 8 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. 14; 15; In this case doing the speculation would create an invalid GEP(@var, 0, 1) and 16; crash. 17 18define i1 @test_constant_speculation() { 19; CHECK-LABEL: @test_constant_speculation( 20; CHECK-NEXT: entry: 21; CHECK-NEXT: br i1 undef, label [[END:%.*]], label [[SELECT:%.*]] 22; CHECK: select: 23; CHECK-NEXT: br label [[END]] 24; CHECK: end: 25; CHECK-NEXT: [[TMP:%.*]] = phi i32* [ null, [[ENTRY:%.*]] ], [ getelementptr inbounds ([[MYSTRUCT:%.*]], %mystruct* @var, i64 0, i32 0), [[SELECT]] ] 26; CHECK-NEXT: [[RES:%.*]] = icmp eq i32* [[TMP]], null 27; CHECK-NEXT: ret i1 [[RES]] 28; 29entry: 30 br i1 undef, label %end, label %select 31 32select: 33 34 %tst = icmp eq i32 1, 0 35 %elt = getelementptr %mystruct, %mystruct* @var, i64 0, i32 0 36 %sel = select i1 %tst, i32* null, i32* %elt 37 br label %end 38 39end: 40 %tmp = phi i32* [null, %entry], [%sel, %select] 41 %res = icmp eq i32* %tmp, null 42 ret i1 %res 43} 44