diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 3882d4cb59e01..a791fc5db6698 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3929,7 +3929,10 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { // Canonicalize select of FP values where NaN and -0.0 are not valid as // minnum/maxnum intrinsics. - if (SIFPOp->hasNoNaNs() && SIFPOp->hasNoSignedZeros()) { + if (SIFPOp->hasNoNaNs() && + (SIFPOp->hasNoSignedZeros() || + (SIFPOp->hasOneUse() && + canIgnoreSignBitOfZero(*SIFPOp->use_begin())))) { Value *X, *Y; if (match(&SI, m_OrdOrUnordFMax(m_Value(X), m_Value(Y)))) { Value *BinIntr = diff --git a/llvm/test/Transforms/InstCombine/minmax-fp.ll b/llvm/test/Transforms/InstCombine/minmax-fp.ll index a8470a20365e9..4ae6905404bbd 100644 --- a/llvm/test/Transforms/InstCombine/minmax-fp.ll +++ b/llvm/test/Transforms/InstCombine/minmax-fp.ll @@ -174,8 +174,7 @@ define i8 @t11(float %a, float %b) { ; Either operand could be NaN, but nnan modifier applied. define i8 @t12(float %a, float %b) { ; CHECK-LABEL: @t12( -; CHECK-NEXT: [[DOTINV:%.*]] = fcmp nnan oge float [[B:%.*]], [[A:%.*]] -; CHECK-NEXT: [[DOTV:%.*]] = select nnan i1 [[DOTINV]], float [[A]], float [[B]] +; CHECK-NEXT: [[DOTV:%.*]] = call nnan float @llvm.minnum.f32(float [[B:%.*]], float [[A:%.*]]) ; CHECK-NEXT: [[TMP1:%.*]] = fptosi float [[DOTV]] to i8 ; CHECK-NEXT: ret i8 [[TMP1]] ;