[llvm] 9d29943 - [DAG] Move foldConstantFPMath() inside FoldConstantArithmetic
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 17 08:06:52 PST 2021
Author: Simon Pilgrim
Date: 2021-12-17T16:06:41Z
New Revision: 9d2994311a347460cc4756b9b722b2383a7e89f7
URL: https://github.com/llvm/llvm-project/commit/9d2994311a347460cc4756b9b722b2383a7e89f7
DIFF: https://github.com/llvm/llvm-project/commit/9d2994311a347460cc4756b9b722b2383a7e89f7.diff
LOG: [DAG] Move foldConstantFPMath() inside FoldConstantArithmetic
Further merging of integer and fp constant folding paths.
This allows us to handle undef vector arguments the same as scalar cases.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/X86/fp-undef.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 450a0fe06878..0b1b491c0b38 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5308,9 +5308,10 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
if (isUndef(Opcode, Ops))
return getUNDEF(VT);
- // Handle the case of two scalars.
+ // Handle binops special cases.
if (NumOps == 2) {
- // TODO: Move foldConstantFPMath here?
+ if (SDValue CFP = foldConstantFPMath(Opcode, DL, VT, Ops[0], Ops[1]))
+ return CFP;
if (auto *C1 = dyn_cast<ConstantSDNode>(Ops[0])) {
if (auto *C2 = dyn_cast<ConstantSDNode>(Ops[1])) {
@@ -5981,9 +5982,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
if (SDValue SV = FoldConstantArithmetic(Opcode, DL, VT, {N1, N2}))
return SV;
- if (SDValue V = foldConstantFPMath(Opcode, DL, VT, N1, N2))
- return V;
-
// Canonicalize an UNDEF to the RHS, even over a constant.
if (N1.isUndef()) {
if (TLI->isCommutativeBinOp(Opcode)) {
diff --git a/llvm/test/CodeGen/X86/fp-undef.ll b/llvm/test/CodeGen/X86/fp-undef.ll
index 1ddc7ed83007..2ae51c6c97e9 100644
--- a/llvm/test/CodeGen/X86/fp-undef.ll
+++ b/llvm/test/CodeGen/X86/fp-undef.ll
@@ -483,7 +483,7 @@ define double @frem_undef_op1_fast_constant_inf(double %x) {
define <2 x double> @fadd_undef_op1_constant_vec(<2 x double> %x) {
; ANY-LABEL: fadd_undef_op1_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fadd <2 x double> <double 42.0, double undef>, undef
ret <2 x double> %r
@@ -492,7 +492,7 @@ define <2 x double> @fadd_undef_op1_constant_vec(<2 x double> %x) {
define <2 x double> @fadd_undef_op0_constant_vec(<2 x double> %x) {
; ANY-LABEL: fadd_undef_op0_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movaps {{.*#+}} xmm0 = <u,NaN>
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fadd <2 x double> undef, <double undef, double 42.0>
ret <2 x double> %r
@@ -501,7 +501,7 @@ define <2 x double> @fadd_undef_op0_constant_vec(<2 x double> %x) {
define <2 x double> @fsub_undef_op1_constant_vec(<2 x double> %x) {
; ANY-LABEL: fsub_undef_op1_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movaps {{.*#+}} xmm0 = <u,NaN>
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fsub <2 x double> <double undef, double 42.0>, undef
ret <2 x double> %r
@@ -510,7 +510,7 @@ define <2 x double> @fsub_undef_op1_constant_vec(<2 x double> %x) {
define <2 x double> @fsub_undef_op0_constant_vec(<2 x double> %x) {
; ANY-LABEL: fsub_undef_op0_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fsub <2 x double> undef, <double 42.0, double undef>
ret <2 x double> %r
@@ -519,7 +519,7 @@ define <2 x double> @fsub_undef_op0_constant_vec(<2 x double> %x) {
define <2 x double> @fmul_undef_op1_constant_vec(<2 x double> %x) {
; ANY-LABEL: fmul_undef_op1_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fmul <2 x double> <double 42.0, double undef>, undef
ret <2 x double> %r
@@ -528,7 +528,7 @@ define <2 x double> @fmul_undef_op1_constant_vec(<2 x double> %x) {
define <2 x double> @fmul_undef_op0_constant_vec(<2 x double> %x) {
; ANY-LABEL: fmul_undef_op0_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movaps {{.*#+}} xmm0 = <u,NaN>
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fmul <2 x double> undef, <double undef, double 42.0>
ret <2 x double> %r
@@ -537,7 +537,7 @@ define <2 x double> @fmul_undef_op0_constant_vec(<2 x double> %x) {
define <2 x double> @fdiv_undef_op1_constant_vec(<2 x double> %x) {
; ANY-LABEL: fdiv_undef_op1_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fdiv <2 x double> <double 42.0, double undef>, undef
ret <2 x double> %r
@@ -546,7 +546,7 @@ define <2 x double> @fdiv_undef_op1_constant_vec(<2 x double> %x) {
define <2 x double> @fdiv_undef_op0_constant_vec(<2 x double> %x) {
; ANY-LABEL: fdiv_undef_op0_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movaps {{.*#+}} xmm0 = <u,NaN>
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = fdiv <2 x double> undef, <double undef, double 42.0>
ret <2 x double> %r
@@ -555,7 +555,7 @@ define <2 x double> @fdiv_undef_op0_constant_vec(<2 x double> %x) {
define <2 x double> @frem_undef_op1_constant_vec(<2 x double> %x) {
; ANY-LABEL: frem_undef_op1_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movaps {{.*#+}} xmm0 = <u,NaN>
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = frem <2 x double> <double undef, double 42.0>, undef
ret <2 x double> %r
@@ -564,7 +564,7 @@ define <2 x double> @frem_undef_op1_constant_vec(<2 x double> %x) {
define <2 x double> @frem_undef_op0_constant_vec(<2 x double> %x) {
; ANY-LABEL: frem_undef_op0_constant_vec:
; ANY: # %bb.0:
-; ANY-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
+; ANY-NEXT: movaps {{.*#+}} xmm0 = [NaN,NaN]
; ANY-NEXT: retq
%r = frem <2 x double> undef, <double 42.0, double undef>
ret <2 x double> %r
More information about the llvm-commits
mailing list