This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] use decomposeBitTestICmp to make icmp (trunc X), C more consistent
ClosedPublic

Authored by spatel on Nov 22 2021, 12:38 PM.

Details

Summary

This is a follow-on suggested in D112634. Two folds that were added with that patch are subsumed in the call to decomposeBitTestICmp, and two other folds are potentially inverted. The deleted folds were very specialized by instcombine standards because they were restricted to legal integer types based on the data layout. This generalizes the canonical form independent of target/types.

This change has a reasonable chance of exposing regressions either in IR or codegen, but I don't have any evidence for either of those yet. A spot check of asm across several in-tree targets shows variations that I expect are mostly neutral.

We have one improvement in an existing IR test that I noted with a comment. Using mask ops might also make more code match with D114272.

Diff Detail

Event Timeline

spatel created this revision.Nov 22 2021, 12:38 PM
spatel requested review of this revision.Nov 22 2021, 12:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 22 2021, 12:38 PM
lebedev.ri accepted this revision.Nov 26 2021, 3:03 AM

LGTM, sorry for the delay, i like this.

This revision is now accepted and ready to land.Nov 26 2021, 3:03 AM

LGTM, sorry for the delay, i like this.

Thanks for the suggestion and review! Let's see if this causes any fallout...

LGTM, sorry for the delay, i like this.

Thanks for the suggestion and review! Let's see if this causes any fallout...

I still think the other patterns should also migrate into decomposeBitTestICmp().
If you don't want to update every single caller, you can always keep the old declaration
around, and make it a wrapper for the new function, and return false if the rhs constant is non-zero.