brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · e98137d Raw
43 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -passes=early-cse -earlycse-debug-hash -S %s | FileCheck %s3 4%mystruct = type { i32 }5 6; @var is global so that *every* GEP argument is Constant.7@var = external global %mystruct8 9; Control flow is to make the dominance tree consider the final icmp before it10; gets to simplify the purely constant one (%tst). Since that icmp uses the11; select that gets considered next. Finally the select simplification looks at12; 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) and16; 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]], null27; CHECK-NEXT:    ret i1 [[RES]]28;29entry:30  br i1 %c, label %end, label %select31 32select:33 34  %tst = icmp eq i32 1, 035  %sel = select i1 %tst, ptr null, ptr @var36  br label %end37 38end:39  %tmp = phi ptr [null, %entry], [%sel, %select]40  %res = icmp eq ptr %tmp, null41  ret i1 %res42}43