New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 44541 - Instcombine hangs with "opt -functionattrs -disable-basicaa -O1"
Summary: Instcombine hangs with "opt -functionattrs -disable-basicaa -O1"
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: release-10.0.0
  Show dependency tree
 
Reported: 2020-01-14 06:12 PST by Mikael Holmén
Modified: 2020-02-10 02:36 PST (History)
7 users (show)

See Also:
Fixed By Commit(s): a148b9e9909db6a592609eb35b4de38c9e67cb8b


Attachments
bbi-37458_x86.ll reproducer (2.65 KB, text/plain)
2020-01-14 06:12 PST, Mikael Holmén
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mikael Holmén 2020-01-14 06:12:58 PST
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.
Comment 1 Mikael Holmén 2020-01-14 23:07:35 PST
(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.
Comment 2 Nikita Popov 2020-01-16 10:13:49 PST
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.
Comment 3 Nikita Popov 2020-01-16 12:50:50 PST
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
}
Comment 4 Mikael Holmén 2020-01-17 05:54:22 PST
(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.
Comment 5 Nikita Popov 2020-01-17 12:07:53 PST
Candidate patch: https://reviews.llvm.org/D72944
Comment 6 Nikita Popov 2020-02-08 12:17:07 PST
Alternative fix from https://reviews.llvm.org/D73849 has landed, keeping this open to track LLVM 10 backport.
Comment 7 Hans Wennborg 2020-02-10 02:36:12 PST
(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