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 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(i1 %c) { 19; CHECK-LABEL: @test_constant_speculation( 20; CHECK-NEXT: entry: 21; CHECK-NEXT: br i1 %c, label [[END:%.*]], label [[SELECT:%.*]] 22; CHECK: select: 23; CHECK-NEXT: br label [[END]] 24; CHECK: 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]] 28; 29entry: 30 br i1 %c, label %end, label %select 31 32select: 33 34 %tst = icmp eq i32 1, 0 35 %sel = select i1 %tst, ptr null, ptr @var 36 br label %end 37 38end: 39 %tmp = phi ptr [null, %entry], [%sel, %select] 40 %res = icmp eq ptr %tmp, null 41 ret i1 %res 42} 43