[llvm] r363080 - [InstCombine] Update fptrunc (fneg x)) -> (fneg (fptrunc x) for unary FNeg
Cameron McInally via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 08:45:41 PDT 2019
Author: mcinally
Date: Tue Jun 11 08:45:41 2019
New Revision: 363080
URL: http://llvm.org/viewvc/llvm-project?rev=363080&view=rev
Log:
[InstCombine] Update fptrunc (fneg x)) -> (fneg (fptrunc x) for unary FNeg
Differential Revision: https://reviews.llvm.org/D62629
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/trunk/test/Transforms/InstCombine/fpcast.ll
llvm/trunk/test/Transforms/InstCombine/fpextend.ll
llvm/trunk/test/Transforms/InstCombine/fsub.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=363080&r1=363079&r2=363080&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Jun 11 08:45:41 2019
@@ -1615,12 +1615,20 @@ Instruction *InstCombiner::visitFPTrunc(
return CastInst::CreateFPCast(ExactResult, Ty);
}
}
+ }
- // (fptrunc (fneg x)) -> (fneg (fptrunc x))
- Value *X;
- if (match(OpI, m_FNeg(m_Value(X)))) {
+ // (fptrunc (fneg x)) -> (fneg (fptrunc x))
+ Value *X;
+ Instruction *Op = dyn_cast<Instruction>(FPT.getOperand(0));
+ if (Op && Op->hasOneUse()) {
+ if (match(Op, m_FNeg(m_Value(X)))) {
Value *InnerTrunc = Builder.CreateFPTrunc(X, Ty);
- return BinaryOperator::CreateFNegFMF(InnerTrunc, OpI);
+
+ // FIXME: Once we're sure that unary FNeg optimizations are on par with
+ // binary FNeg, this should always return a unary operator.
+ if (isa<BinaryOperator>(Op))
+ return BinaryOperator::CreateFNegFMF(InnerTrunc, Op);
+ return UnaryOperator::CreateFNegFMF(InnerTrunc, Op);
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/fpcast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fpcast.ll?rev=363080&r1=363079&r2=363080&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fpcast.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fpcast.ll Tue Jun 11 08:45:41 2019
@@ -40,11 +40,10 @@ define half @fneg_fptrunc(float %a) {
ret half %c
}
-; FIXME: This combine isn't working.
define half @unary_fneg_fptrunc(float %a) {
; CHECK-LABEL: @unary_fneg_fptrunc(
-; CHECK-NEXT: [[B:%.*]] = fneg float [[A:%.*]]
-; CHECK-NEXT: [[C:%.*]] = fptrunc float [[B]] to half
+; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
+; CHECK-NEXT: [[C:%.*]] = fneg half [[TMP1]]
; CHECK-NEXT: ret half [[C]]
;
%b = fneg float %a
@@ -63,11 +62,10 @@ define <2 x half> @fneg_fptrunc_vec_unde
ret <2 x half> %c
}
-; FIXME: This combine isn't working.
define <2 x half> @unary_fneg_fptrunc_vec(<2 x float> %a) {
; CHECK-LABEL: @unary_fneg_fptrunc_vec(
-; CHECK-NEXT: [[B:%.*]] = fneg <2 x float> [[A:%.*]]
-; CHECK-NEXT: [[C:%.*]] = fptrunc <2 x float> [[B]] to <2 x half>
+; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
+; CHECK-NEXT: [[C:%.*]] = fneg <2 x half> [[TMP1]]
; CHECK-NEXT: ret <2 x half> [[C]]
;
%b = fneg <2 x float> %a
@@ -86,11 +84,10 @@ define half @test4-fast(float %a) {
ret half %c
}
-; FIXME: This combine isn't working.
define half @test4_unary_fneg-fast(float %a) {
; CHECK-LABEL: @test4_unary_fneg-fast(
-; CHECK-NEXT: [[B:%.*]] = fneg fast float [[A:%.*]]
-; CHECK-NEXT: [[C:%.*]] = fptrunc float [[B]] to half
+; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
+; CHECK-NEXT: [[C:%.*]] = fneg fast half [[TMP1]]
; CHECK-NEXT: ret half [[C]]
;
%b = fneg fast float %a
Modified: llvm/trunk/test/Transforms/InstCombine/fpextend.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fpextend.ll?rev=363080&r1=363079&r2=363080&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fpextend.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fpextend.ll Tue Jun 11 08:45:41 2019
@@ -55,13 +55,10 @@ entry:
ret float %tmp34
}
-; FIXME: This combine isn't working.
define float @test4_unary_fneg(float %x) nounwind {
; CHECK-LABEL: @test4_unary_fneg(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[TMP1:%.*]] = fpext float [[X:%.*]] to double
-; CHECK-NEXT: [[TMP2:%.*]] = fneg double [[TMP1]]
-; CHECK-NEXT: [[TMP34:%.*]] = fptrunc double [[TMP2]] to float
+; CHECK-NEXT: [[TMP34:%.*]] = fneg float [[X:%.*]]
; CHECK-NEXT: ret float [[TMP34]]
;
entry:
Modified: llvm/trunk/test/Transforms/InstCombine/fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub.ll?rev=363080&r1=363079&r2=363080&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll Tue Jun 11 08:45:41 2019
@@ -345,12 +345,11 @@ define float @neg_trunc_op1_extra_use(do
ret float %t3
}
-; FIXME: This combine isn't working.
define float @unary_neg_trunc_op1_extra_use(double %a, float %b) {
; CHECK-LABEL: @unary_neg_trunc_op1_extra_use(
-; CHECK-NEXT: [[T1:%.*]] = fneg double [[A:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = fptrunc double [[T1]] to float
-; CHECK-NEXT: [[T3:%.*]] = fsub float [[B:%.*]], [[T2]]
+; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[A:%.*]] to float
+; CHECK-NEXT: [[T2:%.*]] = fneg float [[TMP1]]
+; CHECK-NEXT: [[T3:%.*]] = fadd float [[TMP1]], [[B:%.*]]
; CHECK-NEXT: call void @use(float [[T2]])
; CHECK-NEXT: ret float [[T3]]
;
More information about the llvm-commits
mailing list