[PATCH] D151670: Fix crash in X86 ISelLowering: ConstantDataSequential can contain float as well

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 29 18:04:05 PDT 2023


mehdi_amini created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
mehdi_amini requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fixes #62995

Here is a minimal repro:

  // RUN: llc %s -mtriple=x86_64-unknown-linux-gnu   -mcpu="znver4"
  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-unknown-linux-gnu"
  
  declare void @printF32(float)
  
  define void @entry() {
    %L1 = insertelement <4 x float> poison, float 0.000000e+00, i64 1
    %L4 = fadd <4 x float> %L1, zeroinitializer
    %L5 = insertvalue [3 x <4 x float>] undef, <4 x float> %L4, 0
    %L8 = extractvalue [3 x <4 x float>] %L5, 0
    %L9 = extractelement <4 x float> %L8, i64 0
    call void @printF32(float %L9)
    %L10 = extractelement <4 x float> %L8, i64 1
    call void @printF32(float %L10)
    ret void
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151670

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp


Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -7454,8 +7454,15 @@
       Type *Ty = CDS->getType();
       Mask = APInt::getZero(Ty->getPrimitiveSizeInBits());
       unsigned EltBits = CDS->getElementType()->getPrimitiveSizeInBits();
-      for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I)
-        Mask.insertBits(CDS->getElementAsAPInt(I), I * EltBits);
+      if (isa<IntegerType>(CDS->getElementType())) {
+        for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I)
+          Mask.insertBits(CDS->getElementAsAPInt(I), I * EltBits);
+      } else {
+        // Assume floating points
+        for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I)
+          Mask.insertBits(CDS->getElementAsAPFloat(I).bitcastToAPInt(),
+                          I * EltBits);
+      }
       return true;
     }
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151670.526489.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230530/131a86bd/attachment.bin>


More information about the llvm-commits mailing list