This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add combines of icmp (mul nsw/nuw X, C2), C when C % C2 == 0
Needs ReviewPublic

Authored by Nicola on Sep 27 2018, 3:23 AM.

Details

Reviewers
spatel
Summary

I think this is the least tricky part of the combines. The proof for this (and all the others) is here:

The ones implemented here are the ones with the C2 % C1 == 0

Diff Detail

Repository
rL LLVM

Event Timeline

Nicola created this revision.Sep 27 2018, 3:23 AM

There's enough going on here that I'd prefer to split this patch up further. Can you start by handling just the eq/ne predicates? If the remainder is non-zero there, instsimplify should fold this down to a true or false value. Start with that patch?

We're missing tests/proofs for the 'nuw' variants of the eq/ne patterns. Also, what happens if the mul has both nsw and nuw?

lib/Transforms/InstCombine/InstCombineCompares.cpp
1814–1816

We should always bail out of this function if MulC is 0 right at the top. That means instsimplify hasn't run yet on this expression, so we're wasting time on (and potentially obscuring) a pattern that can be completely eliminated.

1819

Sink the creation of ReducedVal. We don't want to do that unless we know the transform will fire.

1821–1823

Don't use braces here according to LLVM coding guidelines.