[llvm] 0954c67 - [DAG] visitFREEZE - only fold integer types to an all ones constant

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 08:47:18 PST 2024


Author: Simon Pilgrim
Date: 2024-12-16T16:46:38Z
New Revision: 0954c67d7ae412af9f8da5149565d9af837ac575

URL: https://github.com/llvm/llvm-project/commit/0954c67d7ae412af9f8da5149565d9af837ac575
DIFF: https://github.com/llvm/llvm-project/commit/0954c67d7ae412af9f8da5149565d9af837ac575.diff

LOG: [DAG] visitFREEZE - only fold integer types to an all ones constant

ISD::isBuildVectorAllOnes can peek through bitcasts, so this can match against FP NAN (ish) data (e.g. double (bitcast i64 -1)) under certain circumstances - bail if the type isn't an integer and let bitcast folding handle it first.

Fixes #120093

Added: 
    llvm/test/CodeGen/X86/pr120093.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 9d888d9940a1cc..4fe5e7416c7871 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -16096,7 +16096,7 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
   if (N0.getOpcode() == ISD::BUILD_VECTOR) {
     SDLoc DL(N0);
     EVT VT = N0.getValueType();
-    if (llvm::ISD::isBuildVectorAllOnes(N0.getNode()))
+    if (llvm::ISD::isBuildVectorAllOnes(N0.getNode()) && VT.isInteger())
       return DAG.getAllOnesConstant(DL, VT);
     if (llvm::ISD::isBuildVectorOfConstantSDNodes(N0.getNode())) {
       SmallVector<SDValue, 8> NewVecC;

diff  --git a/llvm/test/CodeGen/X86/pr120093.ll b/llvm/test/CodeGen/X86/pr120093.ll
new file mode 100644
index 00000000000000..99bf2218c5538f
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr120093.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+
+define double @PR120093() {
+; CHECK-LABEL: PR120093:
+; CHECK:       # %bb.0: # %bb
+; CHECK-NEXT:    xorpd %xmm0, %xmm0
+; CHECK-NEXT:    xorpd %xmm1, %xmm1
+; CHECK-NEXT:    movhpd {{.*#+}} xmm1 = xmm1[0],mem[0]
+; CHECK-NEXT:    cmpnltpd %xmm1, %xmm0
+; CHECK-NEXT:    movmskpd %xmm0, %eax
+; CHECK-NEXT:    cmpl $3, %eax
+; CHECK-NEXT:    jne .LBB0_2
+; CHECK-NEXT:  # %bb.1: # %bb2
+; CHECK-NEXT:    xorpd %xmm0, %xmm0
+; CHECK-NEXT:    retq
+; CHECK-NEXT:  .LBB0_2: # %bb3
+bb:
+  %insertelement = insertelement <2 x double> <double poison, double 0xFFFFFFFFFFFFFFFF>, double 0.000000e+00, i64 0
+  %fcmp = fcmp uge <2 x double> zeroinitializer, %insertelement
+  %extractelement = extractelement <2 x i1> %fcmp, i64 0
+  %extractelement1 = extractelement <2 x i1> %fcmp, i64 1
+  %select = select i1 %extractelement, i1 %extractelement1, i1 false
+  br i1 %select, label %bb2, label %bb3
+
+bb2:                                              ; preds = %bb
+  ret double 0.000000e+00
+
+bb3:                                              ; preds = %bb
+  unreachable
+}


        


More information about the llvm-commits mailing list