This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Remove redundant/bogus mul_with_overflow folds
ClosedPublic

Authored by nikic on Apr 13 2019, 1:35 AM.

Details

Summary

As pointed out in https://reviews.llvm.org/D60518#inline-537280 folding mulo(%x, undef) to {undef, undef} isn't correct. As a correct version of this already exists in InstructionSimplify (https://github.com/llvm-mirror/llvm/blob/bd8056ef326e075cc500f3f0cfcd1193bc200594/lib/Analysis/InstructionSimplify.cpp#L4750-L4757) this is just dead code though. Drop it together with the mul(%x, 0) -> {0, false} fold that is also already handled by InstSimplify.

Diff Detail

Repository
rL LLVM

Event Timeline

nikic created this revision.Apr 13 2019, 1:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2019, 1:35 AM
nikic edited the summary of this revision. (Show Details)Apr 13 2019, 1:35 AM

To be noted, all of these constant-folds should be in instsimplify, not here.

nikic added a comment.Apr 13 2019, 2:32 AM

@lebedev.ri These folds already are in instsimplify, see link in the description.

@lebedev.ri These folds already are in instsimplify, see link in the description.

*these* - yes, i seen the link.
I really meant *all* of the constant-folds that are in this function, let me highlight most(?) of them

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
3966–3968 ↗(On Diff #195005)

not in instsimplify

3990–3992 ↗(On Diff #195005)

not in instsimplify

4014–4016 ↗(On Diff #195005)

not in instsimplify

nikic added a comment.Apr 13 2019, 2:45 AM

@lebedev.ri Those aren't constant folds though. They fold to {%x, false}, which has to be created as something like insertvalue {undef, false}, 0, %x, which is non-constant. Or is the idea here more along the lines of folding extractvalue addo(%x, 0), 1 to false in instsimplify? That would be possible, but doesn't seem like the right thing to do to me.

@lebedev.ri Those aren't constant folds though. They fold to {%x, false}, which has to be created as something like insertvalue {undef, false}, 0, %x, which is non-constant. Or is the idea here more along the lines of folding extractvalue addo(%x, 0), 1 to false in instsimplify? That would be possible, but doesn't seem like the right thing to do to me.

Uhm, i think i have used wrong word.
What i meant is that those folds don't create new instructions (but simply return
one of the arguments, in this case), therefore they should be in instsimplify.
That's the distinction between instcombine vs instsimplify.

nikic added a comment.Apr 13 2019, 3:57 AM

@lebedev.ri Those aren't constant folds though. They fold to {%x, false}, which has to be created as something like insertvalue {undef, false}, 0, %x, which is non-constant. Or is the idea here more along the lines of folding extractvalue addo(%x, 0), 1 to false in instsimplify? That would be possible, but doesn't seem like the right thing to do to me.

Uhm, i think i have used wrong word.
What i meant is that those folds don't create new instructions (but simply return
one of the arguments, in this case), therefore they should be in instsimplify.
That's the distinction between instcombine vs instsimplify.

These folds create new instructions: An insertvalue is needed to create the aggregate. These folds can only be performed in instsimplify is we start matching from extractvalue rather than with.overflow, as we don't need to explicitly construct the aggregate in that case. If we do so, the instcombine folds are still needed though, because we don't necessarily extract from the aggregate (could also return etc.)

lebedev.ri accepted this revision.Apr 13 2019, 4:19 AM

@lebedev.ri Those aren't constant folds though. They fold to {%x, false}, which has to be created as something like insertvalue {undef, false}, 0, %x, which is non-constant. Or is the idea here more along the lines of folding extractvalue addo(%x, 0), 1 to false in instsimplify? That would be possible, but doesn't seem like the right thing to do to me.

Uhm, i think i have used wrong word.
What i meant is that those folds don't create new instructions (but simply return
one of the arguments, in this case), therefore they should be in instsimplify.
That's the distinction between instcombine vs instsimplify.

These folds create new instructions: An insertvalue is needed to create the aggregate. These folds can only be performed in instsimplify is we start matching from extractvalue rather than with.overflow, as we don't need to explicitly construct the aggregate in that case. If we do so, the instcombine folds are still needed though, because we don't necessarily extract from the aggregate (could also return etc.)

Oh wait, i'm reading the https://github.com/llvm-mirror/llvm/blob/bd8056ef326e075cc500f3f0cfcd1193bc200594/lib/Analysis/InstructionSimplify.cpp#L4750-L4757 wrong.
Indeed, despite how they look, they don't already produce insertvalue https://godbolt.org/z/sb_xoT (i thought they did)
So yes, it wouldn't be as simple as just moving these folds from here to there.

Okay, lg.

This revision is now accepted and ready to land.Apr 13 2019, 4:19 AM
This revision was automatically updated to reflect the committed changes.