1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

[InstCombine] avoid breaking up bitcasted vector min/max patterns (PR32306)

As the related tests show, we're not canonicalizing to this form for scalars or vectors yet,
but this solves the immediate problem in:
https://bugs.llvm.org/show_bug.cgi?id=32306

llvm-svn: 297989
This commit is contained in:
Sanjay Patel 2017-03-16 20:42:45 +00:00
parent 77b3b41bd4
commit 7f15f4047b
2 changed files with 14 additions and 3 deletions

View File

@ -120,6 +120,16 @@ static Constant *getSelectFoldableConstant(Instruction *I) {
/// We have (select c, TI, FI), and we know that TI and FI have the same opcode.
Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
Instruction *FI) {
// Don't break up min/max patterns. The hasOneUse checks below prevent that
// for most cases, but vector min/max with bitcasts can be transformed. If the
// one-use restrictions are eased for other patterns, we still don't want to
// obfuscate min/max.
if ((match(&SI, m_SMin(m_Value(), m_Value())) ||
match(&SI, m_SMax(m_Value(), m_Value())) ||
match(&SI, m_UMin(m_Value(), m_Value())) ||
match(&SI, m_UMax(m_Value(), m_Value()))))
return nullptr;
// If this is a cast from the same type, merge.
if (TI->getNumOperands() == 1 && TI->isCast()) {
Type *FIOpndTy = FI->getOperand(0)->getType();

View File

@ -529,15 +529,16 @@ define float @bitcast_scalar_umax(float %x, float %y) {
}
; PR32306 - https://bugs.llvm.org/show_bug.cgi?id=32306
; FIXME: The icmp/select form a canonical smin, so don't hide that by folding the final bitcast into the select.
; The icmp/select form a canonical smin, so don't hide that by folding the final bitcast into the select.
define <8 x float> @bitcast_vector_smin(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @bitcast_vector_smin(
; CHECK-NEXT: [[BCX:%.*]] = bitcast <8 x float> %x to <8 x i32>
; CHECK-NEXT: [[BCY:%.*]] = bitcast <8 x float> %y to <8 x i32>
; CHECK-NEXT: [[CMP:%.*]] = icmp slt <8 x i32> [[BCX]], [[BCY]]
; CHECK-NEXT: [[SEL_V:%.*]] = select <8 x i1> [[CMP]], <8 x float> %x, <8 x float> %y
; CHECK-NEXT: ret <8 x float> [[SEL_V]]
; CHECK-NEXT: [[SEL:%.*]] = select <8 x i1> [[CMP]], <8 x i32> [[BCX]], <8 x i32> [[BCY]]
; CHECK-NEXT: [[BCS:%.*]] = bitcast <8 x i32> [[SEL]] to <8 x float>
; CHECK-NEXT: ret <8 x float> [[BCS]]
;
%bcx = bitcast <8 x float> %x to <8 x i32>
%bcy = bitcast <8 x float> %y to <8 x i32>