This is an archive of the discontinued LLVM Phabricator instance.

[IRBuilder] Always respect inserter/folder
ClosedPublic

Authored by nikic on Feb 18 2020, 12:08 PM.

Details

Summary

Some IRBuilder methods that were originally defined on IRBuilderBase do not respect custom IRBuilder inserters/folders, because those were not accessible prior to D73835. Fix this by making use of existing (and now accessible) IRBuilder methods, which will handle inserters/folders correctly.

There are some changes in OpenMP tests, where bitcasts now get constant folded. I've also highlighted one InstCombine test which now finishes in two rather than three iterations, thanks to new instructions being inserted into the worklist.

Diff Detail

Event Timeline

nikic created this revision.Feb 18 2020, 12:08 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript

Nice work

llvm/test/Transforms/InstCombine/saturating-add-sub.ll
2

IMHO how the folding works internally (folded by IRBuilder instead of InstCombine rule) does not need to be part of a/this regression test. If another test is added to this file requiring 3 rounds, it would raise some confusions.

nikic marked an inline comment as done.Feb 18 2020, 1:26 PM
nikic added inline comments.
llvm/test/Transforms/InstCombine/saturating-add-sub.ll
2

To clarify, "iterations" here is how often InstCombine runs (with a full instruction scan), not how many instructions each run visits. There should be at most two iterations, one to perform folds and one to verify the fixpoint. If there are more iterations, that's a bug in worklist management. I'm currently tracking down all these bugs and annotating tests with -instcombine-infinite-loop-threshold=2 to verify that the issue is indeed fixed.

nhaehnle accepted this revision.Feb 19 2020, 4:16 AM

LGTM. I think it's a pretty reasonable idea to add this threshold check to track down things that should be minor, but can add up in terms of compile-time performance.

This revision is now accepted and ready to land.Feb 19 2020, 4:16 AM
This revision was automatically updated to reflect the committed changes.

There should be at most two iterations, one to perform folds and one to verify the fixpoint. If there are more iterations, that's a bug in worklist management

FWIW, the Attributor uses basically the same scheme. It helps us to monitor iteration increases/decreases of patchs and prevents subtle bugs that would escape the regressions tests but hit the iteration limit in real code.