mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
730509657a
When InstCombine initially populates the worklist, it already performs constant folding and DCE. However, as the instructions are initially visited in program order, this DCE can pick up only the last instruction of a dead chain, the rest would only get picked up in the main InstCombine run. To avoid this, we instead perform the DCE in separate pass over the collected instructions in reverse order, which will allow us to pick up full dead instruction chains. We already need to do this reverse iteration anyway to populate the worklist, so this shouldn't add extra cost. This by itself only fixes a small part of the problem though: The same basic issue also applies during the main InstCombine loop. We generally always want DCE to occur as early as possible, because it will allow one-use folds to happen. Address this by also performing DCE while adding deferred instructions to the main worklist. This drops the number of tests that perform more than 2 InstCombine iterations from ~80 to ~40. There's some spurious test changes due to operand order / icmp toggling. Differential Revision: https://reviews.llvm.org/D75008
71 lines
2.4 KiB
LLVM
71 lines
2.4 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -instcombine -instcombine-infinite-loop-threshold=2 -S | FileCheck %s
|
|
|
|
define i8 @single(i32 %A) {
|
|
; CHECK-LABEL: @single(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[A:%.*]], -128
|
|
; CHECK-NEXT: [[L2:%.*]] = select i1 [[TMP0]], i32 [[A]], i32 -128
|
|
; CHECK-NEXT: [[CONV7:%.*]] = trunc i32 [[L2]] to i8
|
|
; CHECK-NEXT: ret i8 [[CONV7]]
|
|
;
|
|
entry:
|
|
%l1 = icmp slt i32 %A, -128
|
|
%l2 = select i1 %l1, i32 128, i32 %A
|
|
%conv7 = trunc i32 %l2 to i8
|
|
ret i8 %conv7
|
|
}
|
|
|
|
define i8 @double(i32 %A) {
|
|
; CHECK-LABEL: @double(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[A:%.*]], -128
|
|
; CHECK-NEXT: [[L2:%.*]] = select i1 [[TMP0]], i32 [[A]], i32 -128
|
|
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[L2]], 127
|
|
; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = select i1 [[TMP1]], i32 [[L2]], i32 127
|
|
; CHECK-NEXT: [[CONV7:%.*]] = trunc i32 [[SPEC_SELECT_I]] to i8
|
|
; CHECK-NEXT: ret i8 [[CONV7]]
|
|
;
|
|
entry:
|
|
%l1 = icmp slt i32 %A, -128
|
|
%l2 = select i1 %l1, i32 128, i32 %A
|
|
%.inv = icmp sgt i32 %A, 127
|
|
%spec.select.i = select i1 %.inv, i32 127, i32 %l2
|
|
%conv7 = trunc i32 %spec.select.i to i8
|
|
ret i8 %conv7
|
|
}
|
|
|
|
define i8 @thisdoesnotloop(i32 %A, i32 %B) {
|
|
; CHECK-LABEL: @thisdoesnotloop(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[L1:%.*]] = icmp slt i32 [[A:%.*]], -128
|
|
; CHECK-NEXT: [[TMP0:%.*]] = trunc i32 [[B:%.*]] to i8
|
|
; CHECK-NEXT: [[CONV7:%.*]] = select i1 [[L1]], i8 -128, i8 [[TMP0]]
|
|
; CHECK-NEXT: ret i8 [[CONV7]]
|
|
;
|
|
entry:
|
|
%l1 = icmp slt i32 %A, -128
|
|
%l2 = select i1 %l1, i32 128, i32 %B
|
|
%conv7 = trunc i32 %l2 to i8
|
|
ret i8 %conv7
|
|
}
|
|
|
|
define i8 @original(i32 %A, i32 %B) {
|
|
; CHECK-LABEL: @original(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], -128
|
|
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[A]], i32 -128
|
|
; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP2]], 127
|
|
; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = select i1 [[TMP3]], i32 [[TMP2]], i32 127
|
|
; CHECK-NEXT: [[CONV7:%.*]] = trunc i32 [[SPEC_SELECT_I]] to i8
|
|
; CHECK-NEXT: ret i8 [[CONV7]]
|
|
;
|
|
%cmp4.i = icmp slt i32 127, %A
|
|
%cmp6.i = icmp sle i32 -128, %A
|
|
%retval.0.i = select i1 %cmp4.i, i32 127, i32 -128
|
|
%not.cmp4.i = xor i1 %cmp4.i, true
|
|
%cleanup.dest.slot.0.i = and i1 %cmp6.i, %not.cmp4.i
|
|
%spec.select.i = select i1 %cleanup.dest.slot.0.i, i32 %A, i32 %retval.0.i
|
|
%conv7 = trunc i32 %spec.select.i to i8
|
|
ret i8 %conv7
|
|
}
|