Skip to content

instcombine transform ruins simplifycfg if-then to select optimization #49769

@valerydmit

Description

@valerydmit
Bugzilla Link 50425
Version trunk
OS Linux
CC @LebedevRI,@RKSimon,@rotateright

Extended Description

I recently encountered a case where instcombine transform
icmp (A-B), (C-B) -> icmp A, C
affects simplifycfg ability to fold if-then into a select.

Here is test case:
; begin
target triple = "x86_64-unknown-linux-gnu"

define dso_local void @​foo(i32* %p1, i32* %p2, i32 %g, i32 %gh) {
entry:
%i2 = load i32, i32* %p1, align 4
%sub17 = sub nsw i32 %i2, %gh
store i32 %sub17, i32* %p1, align 4
%i3 = load i32, i32* %p2, align 4
%i20 = add nsw i32 %i3, %g
%sub21 = sub nsw i32 %i20, %gh
%cmp24 = icmp slt i32 %sub17, %sub21
br i1 %cmp24, label %if.then25, label %if.end28

if.then25:
store i32 %sub21, i32* %p1, align 4
br label %if.end28

if.end28:
br label %end

end:
ret void
}
; end

To reproduce compare
opt -S -instcombine -simplifycfg test.ll
versus
opt -S -simplifycfg test.ll

At first glance it may appear as if instcombine sinking creates an issue for simplifycfg
but even with -instcombine-code-sinking=false option simplifycfg does not fold if-then:

https://alive2.llvm.org/ce/z/sYXoZO

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillallvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions