diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -631,7 +631,7 @@ DenseSet &TrueBiasedRegionsGlobal, DenseSet &FalseBiasedRegionsGlobal, DenseMap &BranchBiasMap) { - if (!BI->isConditional()) + if (!BI->isConditional() || isa(BI->getCondition())) return false; BranchProbability ThenProb, ElseProb; if (!extractBranchProbabilities(BI, ThenProb, ElseProb)) diff --git a/llvm/test/Transforms/PGOProfile/chr-poison.ll b/llvm/test/Transforms/PGOProfile/chr-poison.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/PGOProfile/chr-poison.ll @@ -0,0 +1,76 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -passes='require,function(chr)' -S | FileCheck %s + +; Make sure nothing happens. We must not combine a "poison" branch +; with any other branch. +define void @chr_poison(i1 %arg) !prof !29 { +; CHECK-LABEL: @chr_poison( +; CHECK-NEXT: br i1 false, label [[BB3:%.*]], label [[BB2:%.*]] +; CHECK: bb2: +; CHECK-NEXT: ret void +; CHECK: bb3: +; CHECK-NEXT: br i1 poison, label [[BB5:%.*]], label [[BB4:%.*]], !prof [[PROF30:![0-9]+]] +; CHECK: bb4: +; CHECK-NEXT: br label [[BB5]] +; CHECK: bb5: +; CHECK-NEXT: br i1 [[ARG:%.*]], label [[BB2]], label [[BB6:%.*]], !prof [[PROF31:![0-9]+]] +; CHECK: bb6: +; CHECK-NEXT: br label [[BB2]] +; CHECK: bb7: +; CHECK-NEXT: br label [[BB5]] +; + br i1 false, label %bb3, label %bb2 + +bb2: + ret void + +bb3: + br i1 poison, label %bb5, label %bb4, !prof !30 + +bb4: + br label %bb5 + +bb5: + br i1 %arg, label %bb2, label %bb6, !prof !31 + +bb6: + br label %bb2 + +bb7: + br label %bb5 +} + +!llvm.module.flags = !{!0} + +!0 = !{i32 1, !"ProfileSummary", !1} +!1 = !{!2, !3, !4, !5, !6, !7, !8, !9, !10, !11} +!2 = !{!"ProfileFormat", !"SampleProfile"} +!3 = !{!"TotalCount", i64 2625732223} +!4 = !{!"MaxCount", i64 6099111} +!5 = !{!"MaxInternalCount", i64 0} +!6 = !{!"MaxFunctionCount", i64 8812263} +!7 = !{!"NumCounts", i64 1399554} +!8 = !{!"NumFunctions", i64 14940} +!9 = !{!"IsPartialProfile", i64 0} +!10 = !{!"PartialProfileRatio", double 0.000000e+00} +!11 = !{!"DetailedSummary", !12} +!12 = !{!13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28} +!13 = !{i32 10000, i64 6099103, i32 8} +!14 = !{i32 100000, i64 6083920, i32 44} +!15 = !{i32 200000, i64 5615450, i32 92} +!16 = !{i32 300000, i64 658615, i32 301} +!17 = !{i32 400000, i64 276706, i32 1049} +!18 = !{i32 500000, i64 224143, i32 2110} +!19 = !{i32 600000, i64 155027, i32 3480} +!20 = !{i32 700000, i64 62158, i32 6258} +!21 = !{i32 800000, i64 29875, i32 12602} +!22 = !{i32 900000, i64 5684, i32 34979} +!23 = !{i32 950000, i64 1439, i32 81728} +!24 = !{i32 990000, i64 319, i32 227620} +!25 = !{i32 999000, i64 34, i32 416158} +!26 = !{i32 999900, i64 4, i32 603970} +!27 = !{i32 999990, i64 1, i32 750171} +!28 = !{i32 999999, i64 1, i32 750171} +!29 = !{!"function_entry_count", i64 3204} +!30 = !{!"branch_weights", i32 2126980204, i32 20503444} +!31 = !{!"branch_weights", i32 997, i32 2}