[PGO] Skip if an IndirectBrInst critical edge cannot be split
authorFangrui Song <i@maskray.me>
Thu, 10 Sep 2020 18:03:48 +0000 (11:03 -0700)
committerFangrui Song <i@maskray.me>
Thu, 10 Sep 2020 18:04:14 +0000 (11:04 -0700)
commita0ffe2b21a5159f3f8eed8e98e488e723aa7cab3
tree894829b6a346235f63a1d3b9859f47aab93c3731
parent6040d525507ba8a2593f0906259d012725b6aed2
[PGO] Skip if an IndirectBrInst critical edge cannot be split

PGOInstrumentation runs `SplitIndirectBrCriticalEdges` but some IndirectBrInst
critical edge cannot be split. `getInstrBB` will crash when calling `SplitCriticalEdge`, e.g.

  int foo(char *p) {
    void *targets[2];
    targets[0] = &&indirect;
    targets[1] = &&end;
    for (;; p++)
      if (*p == 7) {
  indirect:
        goto *targets[p[1]]; // the self loop is critical in -O
      }
  end:
    return 0;
  }

Skip such critical edges to prevent a crash.

Reviewed By: davidxl, lebedev.ri

Differential Revision: https://reviews.llvm.org/D87435
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/split-indirectbr-critical-edges.ll