[PATCH] D117184: Fix failing assertion in SimplifyCFG.cpp as icmp gep fold to constant expression [NFC]

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 17 02:04:25 PST 2022


nikic added a subscriber: markus.
nikic added a comment.

In D117184#3247815 <https://reviews.llvm.org/D117184#3247815>, @pvellien wrote:

> Hi @nikic 
> https://gist.github.com/pvellien/e4f519d17b25adf10fdd5978ee0b1de9 
> After trying a lot, this is minimal IR i can able to find. It is reduction from 84k lines to 617 lines. 
> Please compile with Opt with O3 <https://reviews.llvm.org/owners/package/3/>.

Thanks!

Here's what I did: Create a `crash.sh` with:

  #!/bin/sh
  ! build/bin/opt -S -O2 -o /dev/null < $1

And then run `build/bin/llvm-reduce --test crash.sh input.ll`. This produces a 424 line file.

Then I ran `llvm/utils/reduce_pipeline.py --opt-binary build/bin/opt --passes 'default<O2>' --input reduced.ll --output output.ll`. This produces a 231 line file (https://gist.github.com/nikic/9abff537ba4641543951c8d06aa35a3b) and a reduced pipeline: `-passes="cgscc(devirt<4>(inline,function-attrs,function<eager-inv>(instcombine,loop-mssa(licm,loop-rotate),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts>,instcombine,loop(loop-unroll-full),sroa,jump-threading,memcpyopt))),function<eager-inv>(simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts>)"`

For some reason, the pipeline does not get reduced further (cc @markus) even though we can run the first part (the cgscc pipeline) and then feed it into the second part (the function pipeline). This gets us down to https://gist.github.com/nikic/506f4dd532e313ac5b3dcd2759fd209a and `-passes="simplifycfg<switch-to-lookup>"`.

Now we can run it through llvm-reduce again, and get this reduction: https://gist.github.com/nikic/3d15c42b7b8f54e6253215576a4cba07 Using `opt -S -metarenamer` we can clean up the symbol names. With a tiny bit of manual cleanup we get this test case:

  ; RUN: opt -S -passes="simplifycfg<switch-to-lookup>" < %s | FileCheck %s
  
  target triple = "x86_64-unknown-linux-gnu"
  
  %struct.ham = type <{ i32, i32, i32, i8, i8, [2 x i8] }>
  
  @global = external constant [75 x { i32, i32, i32, i8, i8 }]
  
  define i1 @zot(i32 %arg) {
  bb:
    %tmp = icmp eq i32 %arg, 1
    br i1 %tmp, label %bb6, label %bb1
  
  bb1:                                              ; preds = %bb
    %tmp2 = icmp eq i32 %arg, 2
    br i1 %tmp2, label %bb6, label %bb3
  
  bb3:                                              ; preds = %bb1
    %tmp4 = icmp eq i32 %arg, 0
    br i1 %tmp4, label %bb6, label %bb5
  
  bb5:                                              ; preds = %bb3
    br label %bb6
  
  bb6:                                              ; preds = %bb5, %bb3, %bb1, %bb
    %tmp7 = phi %struct.ham* [ null, %bb5 ], [ bitcast (i32* getelementptr inbounds ([75 x { i32, i32, i32, i8, i8 }], [75 x { i32, i32, i32, i8, i8 }]* @global, i64 0, i64 6, i32 0) to %struct.ham*), %bb ], [ null, %bb1 ], [ null, %bb3 ]
    %tmp8 = icmp eq %struct.ham* %tmp7, bitcast (i32* getelementptr inbounds ([75 x { i32, i32, i32, i8, i8 }], [75 x { i32, i32, i32, i8, i8 }]* @global, i64 1, i64 0, i32 0) to %struct.ham*)
    ret i1 %tmp8
  }


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

https://reviews.llvm.org/D117184



More information about the llvm-commits mailing list