2019-04-17 12:52:47 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
|
|
; RUN: opt %s -instcombine -S | FileCheck %s
|
|
|
|
|
|
|
|
define i32 @PR38915(i32 %x, i32 %y, i32 %z) {
|
|
|
|
; CHECK-LABEL: @PR38915(
|
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], -1
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[Y:%.*]], -1
|
[InstCombine] Process newly inserted instructions in the correct order
InstCombine operates on the basic premise that the operands of the
currently processed instruction have already been simplified. It
achieves this by pushing instructions to the worklist in reverse
program order, so that instructions are popped off in program order.
The worklist management in the main combining loop also makes sure
to uphold this invariant.
However, the same is not true for all the code that is performing
manual worklist management. The largest problem (addressed in this
patch) are instructions inserted by InstCombine's IRBuilder. These
will be pushed onto the worklist in order of insertion (generally
matching program order), which means that a) the users of the
original instruction will be visited first, as they are pushed later
in the main loop and b) the newly inserted instructions will be
visited in reverse program order.
This causes a number of problems: First, folds operate on instructions
that have not had their operands simplified, which may result in
optimizations being missed (ran into this in
https://reviews.llvm.org/D72048#1800424, which was the original
motivation for this patch). Additionally, this increases the amount
of folds InstCombine has to perform, both within one iteration, and
by increasing the number of total iterations.
This patch addresses the issue by adding a Worklist.AddDeferred()
method, which is used for instructions inserted by IRBuilder. These
will only be added to the real worklist after the combine finished,
and in reverse order, so they will end up processed in program order.
I should note that the same should also be done to nearly all other
uses of Worklist.Add(), but I'm starting with just this occurrence,
which has by far the largest test fallout.
Most of the test changes are due to
https://bugs.llvm.org/show_bug.cgi?id=44521 or other cases where
we don't canonicalize something. These are neutral. One regression
has been addressed in D73575 and D73647. The remaining regression
in an shl+sdiv fold can't really be fixed without dropping another
transform, but does not seem particularly problematic in the first
place.
Differential Revision: https://reviews.llvm.org/D73411
2020-01-02 00:56:37 +08:00
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP1]], [[TMP2]]
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: [[M1N:%.*]] = select i1 [[TMP3]], i32 [[TMP1]], i32 [[TMP2]]
|
|
|
|
; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[M1N]], [[Z:%.*]]
|
|
|
|
; CHECK-NEXT: [[M2:%.*]] = select i1 [[C2]], i32 [[M1N]], i32 [[Z]]
|
|
|
|
; CHECK-NEXT: [[M2N:%.*]] = xor i32 [[M2]], -1
|
|
|
|
; CHECK-NEXT: ret i32 [[M2N]]
|
|
|
|
;
|
|
|
|
%xn = sub i32 0, %x
|
|
|
|
%yn = sub i32 0, %y
|
|
|
|
%c1 = icmp sgt i32 %xn, %yn
|
|
|
|
%m1 = select i1 %c1, i32 %xn, i32 %yn
|
|
|
|
%m1n = xor i32 %m1, -1
|
|
|
|
%c2 = icmp sgt i32 %m1n, %z
|
|
|
|
%m2 = select i1 %c2, i32 %m1n, i32 %z
|
|
|
|
%m2n = xor i32 %m2, -1
|
|
|
|
ret i32 %m2n
|
|
|
|
}
|