[llvm] r362954 - [InstCombine] allow unordered preds when canonicalizing to fabs()
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 08:39:00 PDT 2019
Author: spatel
Date: Mon Jun 10 08:39:00 2019
New Revision: 362954
URL: http://llvm.org/viewvc/llvm-project?rev=362954&view=rev
Log:
[InstCombine] allow unordered preds when canonicalizing to fabs()
We have a known-never-nan value via 'nnan', so an unordered predicate
is the same as its ordered sibling.
Similar to:
rL362937
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/trunk/test/Transforms/InstCombine/fabs.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=362954&r1=362953&r2=362954&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Mon Jun 10 08:39:00 2019
@@ -1879,7 +1879,7 @@ Instruction *InstCombiner::visitSelectIn
if (match(CondVal, m_FCmp(Pred, m_Specific(FalseVal), m_AnyZeroFP())) &&
match(TrueVal, m_FSub(m_PosZeroFP(), m_Specific(FalseVal))) &&
match(TrueVal, m_Instruction(FSub)) && FSub->hasNoNaNs() &&
- Pred == FCmpInst::FCMP_OLE) {
+ (Pred == FCmpInst::FCMP_OLE || Pred == FCmpInst::FCMP_ULE)) {
Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, FalseVal, FSub);
return replaceInstUsesWith(SI, Fabs);
}
@@ -1887,7 +1887,7 @@ Instruction *InstCombiner::visitSelectIn
if (match(CondVal, m_FCmp(Pred, m_Specific(TrueVal), m_AnyZeroFP())) &&
match(FalseVal, m_FSub(m_PosZeroFP(), m_Specific(TrueVal))) &&
match(FalseVal, m_Instruction(FSub)) && FSub->hasNoNaNs() &&
- Pred == FCmpInst::FCMP_OGT) {
+ (Pred == FCmpInst::FCMP_OGT || Pred == FCmpInst::FCMP_UGT)) {
Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, TrueVal, FSub);
return replaceInstUsesWith(SI, Fabs);
}
Modified: llvm/trunk/test/Transforms/InstCombine/fabs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fabs.ll?rev=362954&r1=362953&r2=362954&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fabs.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fabs.ll Mon Jun 10 08:39:00 2019
@@ -279,10 +279,8 @@ define double @select_fcmp_nnan_ole_zero
define double @select_fcmp_nnan_ule_zero(double %x) {
; CHECK-LABEL: @select_fcmp_nnan_ule_zero(
-; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ule double [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[NEGX:%.*]] = fsub nnan double 0.000000e+00, [[X]]
-; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]]
-; CHECK-NEXT: ret double [[FABS]]
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan double @llvm.fabs.f64(double [[X:%.*]])
+; CHECK-NEXT: ret double [[TMP1]]
;
%lezero = fcmp ule double %x, 0.0
%negx = fsub nnan double 0.0, %x
@@ -348,10 +346,8 @@ define half @select_fcmp_nnan_ogt_negzer
define half @select_fcmp_nnan_ugt_negzero(half %x) {
; CHECK-LABEL: @select_fcmp_nnan_ugt_negzero(
-; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ugt half [[X:%.*]], 0xH0000
-; CHECK-NEXT: [[NEGX:%.*]] = fsub nnan half 0xH0000, [[X]]
-; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]]
-; CHECK-NEXT: ret half [[FABS]]
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan half @llvm.fabs.f16(half [[X:%.*]])
+; CHECK-NEXT: ret half [[TMP1]]
;
%gtzero = fcmp ugt half %x, -0.0
%negx = fsub nnan half 0.0, %x
More information about the llvm-commits
mailing list