[PATCH] D100213: [PassManager][PhaseOrdering] lower expects before running simplifyCFG

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 06:49:04 PDT 2021


spatel added a comment.

In D100213#2992583 <https://reviews.llvm.org/D100213#2992583>, @nikic wrote:

> FYI this seems to break expect intrinsics in rust (https://github.com/rust-lang/rust/issues/88767). It looks like the IR generated by rust requires the SimplifyCFG+SROA+EarlyCSE sequence that was previously used in order to bring the expect intrinsics into a form that LowerExpectIntrinsic understands.

The lowering of llvm.expect in the optimizer is very fragile. Either we need to:
(1) alter the front-end so expect is placed closer to its user (I have no idea if that is feasible)
(2) enhance -lower-expect to look through complicated sequences
(3) run -lower-expect multiple times -- and in different modes, so it doesn't immediately kill expects that it doesn't match up to branches

In the rust example, we have this unoptimized sequence:

    %2 = call i1 @llvm.expect.i1(i1 %a, i1 false), !dbg !10
    %3 = zext i1 %2 to i8, !dbg !10
    store i8 %3, i8* %0, align 1, !dbg !10
    %4 = load i8, i8* %0, align 1, !dbg !10, !range !11
    %_2 = trunc i8 %4 to i1, !dbg !10
    br label %bb1, !dbg !10
  
  bb1:                                              ; preds = %start
    br i1 %_2, label %bb2, label %bb3, !dbg !10

We need both -simplifycfg (to get the branch into the same block as the expect) and -early-cse (to eliminate the round-trip through memory and the casts). Otherwise, we just drop the expect instead of transforming it into metadata with -lower-expect.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100213/new/

https://reviews.llvm.org/D100213



More information about the llvm-commits mailing list