Created attachment 23015 [details] bbi-37458_x86.ll reproducer Running opt -functionattrs -disable-basicaa -O1 -S -o - ./bbi-37458_x86.ll seems to hang forever. Adding -debug-pass=Executions shows [2020-01-14 15:08:50.872376271] 0x611e690 Executing Pass 'Combine redundant instructions' on Function 'test_sub3_4'... and adding -debug gives repeated occurences of IC: Visiting: %_tmp2687 = select i1 %1808, i16 0, i16 %_tmp2685 IC: Visiting: %1808 = icmp sgt i16 0, %_tmp2685 IC: Mod = %1808 = icmp sgt i16 0, %_tmp2685 New = %1808 = icmp slt i16 %_tmp2682, 0 IC: ADD: %_tmp2687 = select i1 %1808, i16 0, i16 %_tmp2685 IC: ADD: %1808 = icmp slt i16 %_tmp2682, 0 IC: Visiting: %1808 = icmp slt i16 %_tmp2682, 0 IC: Visiting: %_tmp2687 = select i1 %1808, i16 0, i16 %_tmp2685 I've tried to reduce the command line to some minor variation of just opt -instcombine but I can't seem to manage that. :/ The problem seems to be fairly old, I've seen it in builds from around late March 2019.
(In reply to Mikael Holmén from comment #0) > > The problem seems to be fairly old, I've seen it in builds from around late > March 2019. It starts failing with 3af5b28f4: [ValueTracking] Use ConstantRange based overflow check for signed sub No idea if it's a coincidence or if 3af5b28f4 is actually doing something weird.
The reason this might not be reproducible standalone is that apparently there is no way right now to disable expensive combines in "opt -instcombine". I always thought those were default disabled in that case, but looking at the code, even doing something like "opt -expensive-combines=0" is still going to run them. This is relevant here, because it determines whether the @idusf() calls get constant folded.
Here's a reduced test case based on https://reviews.llvm.org/D72861 and opt -instcombine -expensive-combines=0: declare i16 @llvm.ssub.sat.i16(i16, i16) define i16 @passthru(i16 returned %x) { ret i16 %x } define i16 @test(i16 %arg) { %zero = call i16 @passthru(i16 0) %sub = call i16 @llvm.ssub.sat.i16(i16 %arg, i16 %zero) %cmp = icmp slt i16 %sub, 0 %ret = select i1 %cmp, i16 0, i16 %sub ret i16 %ret }
(In reply to Nikita Popov from comment #2) > The reason this might not be reproducible standalone is that apparently > there is no way right now to disable expensive combines in "opt > -instcombine". I always thought those were default disabled in that case, > but looking at the code, even doing something like "opt > -expensive-combines=0" is still going to run them. > > This is relevant here, because it determines whether the @idusf() calls get > constant folded. Aha nice, that explains why it was hard. Thanks for looking into this.
Candidate patch: https://reviews.llvm.org/D72944
Alternative fix from https://reviews.llvm.org/D73849 has landed, keeping this open to track LLVM 10 backport.
(In reply to Nikita Popov from comment #6) > Alternative fix from https://reviews.llvm.org/D73849 has landed, keeping > this open to track LLVM 10 backport. Cherry-picked as fc12083cbc5caa0e60a8e12bab9c34f71a4b31b1