diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -1392,7 +1392,7 @@ } /// Test whether the given two constants can be allocated the same constant pool -/// entry. +/// entry referenced by \param A. static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B, const DataLayout &DL) { // Handle the trivial case quickly. @@ -1412,6 +1412,8 @@ if (StoreSize != DL.getTypeStoreSize(B->getType()) || StoreSize > 128) return false; + bool ContainsUndefOrPoisonA = A->containsUndefOrPoisonElement(); + Type *IntTy = IntegerType::get(A->getContext(), StoreSize*8); // Try constant folding a bitcast of both instructions to an integer. If we @@ -1431,7 +1433,14 @@ B = ConstantFoldCastOperand(Instruction::BitCast, const_cast(B), IntTy, DL); - return A == B; + if (A != B) + return false; + + // Constants only safely match if A doesn't contain undef/poison. + // As we'll be reusing A, it doesn't matter if B contain undef/poison. + // TODO: Handle cases where A and B have the same undef/poison elements. + // TODO: Merge A and B with mismatching undef/poison elements. + return !ContainsUndefOrPoisonA; } /// Create a new entry in the constant pool or return an existing one. diff --git a/llvm/test/CodeGen/X86/pr63108.ll b/llvm/test/CodeGen/X86/pr63108.ll --- a/llvm/test/CodeGen/X86/pr63108.ll +++ b/llvm/test/CodeGen/X86/pr63108.ll @@ -4,8 +4,6 @@ ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=AVX2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64-v4 | FileCheck %s --check-prefixes=AVX512 -; FIXME: %vector.body.preheader <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> constant should be <251,223,0,0,0,0,0,0,0,0,0,0,0,0,0,0> - define i32 @PR63108() { ; SSE-LABEL: PR63108: ; SSE: # %bb.0: # %entry @@ -17,7 +15,7 @@ ; SSE-NEXT: jmp .LBB0_5 ; SSE-NEXT: .LBB0_2: # %vector.body.preheader ; SSE-NEXT: pxor %xmm0, %xmm0 -; SSE-NEXT: movdqa {{.*#+}} xmm2 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> +; SSE-NEXT: movdqa {{.*#+}} xmm2 = [57339,0,0,0] ; SSE-NEXT: xorl %eax, %eax ; SSE-NEXT: .p2align 4, 0x90 ; SSE-NEXT: .LBB0_3: # %vector.body @@ -51,7 +49,7 @@ ; AVX1-NEXT: vmovdqa {{.*#+}} xmm0 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> ; AVX1-NEXT: jmp .LBB0_5 ; AVX1-NEXT: .LBB0_2: # %vector.body.preheader -; AVX1-NEXT: vmovaps {{.*#+}} xmm0 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> +; AVX1-NEXT: vmovaps {{.*#+}} xmm0 = [57339,0,0,0] ; AVX1-NEXT: xorl %eax, %eax ; AVX1-NEXT: .p2align 4, 0x90 ; AVX1-NEXT: .LBB0_3: # %vector.body @@ -88,7 +86,7 @@ ; AVX2-NEXT: vmovdqa {{.*#+}} xmm0 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> ; AVX2-NEXT: jmp .LBB0_5 ; AVX2-NEXT: .LBB0_2: # %vector.body.preheader -; AVX2-NEXT: vmovdqa {{.*#+}} xmm0 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> +; AVX2-NEXT: vmovdqa {{.*#+}} xmm0 = [57339,0,0,0] ; AVX2-NEXT: xorl %eax, %eax ; AVX2-NEXT: .p2align 4, 0x90 ; AVX2-NEXT: .LBB0_3: # %vector.body @@ -125,7 +123,7 @@ ; AVX512-NEXT: vmovdqa {{.*#+}} xmm0 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> ; AVX512-NEXT: jmp .LBB0_5 ; AVX512-NEXT: .LBB0_2: # %vector.body.preheader -; AVX512-NEXT: vmovdqa {{.*#+}} xmm0 = <251,223,u,u,u,u,u,u,u,u,u,u,u,u,u,u> +; AVX512-NEXT: vmovdqa {{.*#+}} xmm0 = [57339,0,0,0] ; AVX512-NEXT: xorl %eax, %eax ; AVX512-NEXT: .p2align 4, 0x90 ; AVX512-NEXT: .LBB0_3: # %vector.body