[InstCombine] Fix store merge worklist management (PR46680)
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 18 Jul 2020 20:22:41 +0000 (22:22 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 19 Jul 2020 13:05:45 +0000 (15:05 +0200)
commitd12ec0f752e7f2c7f7252539da2d124264ec33f7
treea53ce188ac999972ec4b890b1e45fba523a3b9be
parent3504acc33e8b9ddd7de71d75cdc329a14dbf58d9
[InstCombine] Fix store merge worklist management (PR46680)

Fixes https://bugs.llvm.org/show_bug.cgi?id=46680.

Just like insertions through IRBuilder, InsertNewInstBefore()
should be using the deferred worklist mechanism, so that processing
of newly added instructions is prioritized.

There's one side-effect of the worklist order change which could be
classified as a regression. An add op gets pushed through a select
that at the time is not a umax. We could add a reverse transform
that tries to push adds in the reverse direction to restore a min/max,
but that seems like a sure way of getting infinite loops... Seems
like something that should best wait on min/max intrinsics.

Differential Revision: https://reviews.llvm.org/D84109
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/minmax-fold.ll
llvm/test/Transforms/InstCombine/pr46680.ll