mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
8017c13c9d
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
19 lines
551 B
LLVM
19 lines
551 B
LLVM
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
define i32 @foo(i32 %x, i32 %y) {
|
|
; CHECK-LABEL: foo
|
|
; CHECK: [[TMP1:%.*]] = icmp ugt i32 %x, %y
|
|
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 %x, i32 %y, !prof ![[$MD0:[0-9]+]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP2]], -1
|
|
; CHECK-NEXT: ret i32 [[TMP3:%.*]]
|
|
; CHECK-DAG: !0 = !{!"branch_weights", i32 6, i32 1}
|
|
|
|
%1 = xor i32 %x, -1
|
|
%2 = xor i32 %y, -1
|
|
%3 = icmp ugt i32 %1, %2
|
|
%4 = select i1 %3, i32 %2, i32 %1, !prof !1
|
|
ret i32 %4
|
|
}
|
|
|
|
!1 = !{!"branch_weights", i32 1, i32 6}
|