[X86] X86FixupVectorConstants - create f32/f64 broadcast constants if the source constant data was ANY floating point type
We don't need an exact match, this is mainly cleanup for cases where v2f32 style types have been cast to f64 etc.
This commit is contained in:
@@ -190,12 +190,13 @@ static Constant *rebuildSplatableConstant(const Constant *C,
|
||||
Type *SclTy = OriginalType->getScalarType();
|
||||
unsigned NumSclBits = SclTy->getPrimitiveSizeInBits();
|
||||
NumSclBits = std::min<unsigned>(NumSclBits, SplatBitWidth);
|
||||
LLVMContext &Ctx = OriginalType->getContext();
|
||||
|
||||
if (NumSclBits == 8) {
|
||||
SmallVector<uint8_t> RawBits;
|
||||
for (unsigned I = 0; I != SplatBitWidth; I += 8)
|
||||
RawBits.push_back(Splat->extractBits(8, I).getZExtValue());
|
||||
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
|
||||
return ConstantDataVector::get(Ctx, RawBits);
|
||||
}
|
||||
|
||||
if (NumSclBits == 16) {
|
||||
@@ -204,25 +205,25 @@ static Constant *rebuildSplatableConstant(const Constant *C,
|
||||
RawBits.push_back(Splat->extractBits(16, I).getZExtValue());
|
||||
if (SclTy->is16bitFPTy())
|
||||
return ConstantDataVector::getFP(SclTy, RawBits);
|
||||
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
|
||||
return ConstantDataVector::get(Ctx, RawBits);
|
||||
}
|
||||
|
||||
if (NumSclBits == 32) {
|
||||
SmallVector<uint32_t> RawBits;
|
||||
for (unsigned I = 0; I != SplatBitWidth; I += 32)
|
||||
RawBits.push_back(Splat->extractBits(32, I).getZExtValue());
|
||||
if (SclTy->isFloatTy())
|
||||
return ConstantDataVector::getFP(SclTy, RawBits);
|
||||
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
|
||||
if (SclTy->isFloatingPointTy())
|
||||
return ConstantDataVector::getFP(Type::getFloatTy(Ctx), RawBits);
|
||||
return ConstantDataVector::get(Ctx, RawBits);
|
||||
}
|
||||
|
||||
// Fallback to i64 / double.
|
||||
SmallVector<uint64_t> RawBits;
|
||||
for (unsigned I = 0; I != SplatBitWidth; I += 64)
|
||||
RawBits.push_back(Splat->extractBits(64, I).getZExtValue());
|
||||
if (SclTy->isDoubleTy())
|
||||
return ConstantDataVector::getFP(SclTy, RawBits);
|
||||
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
|
||||
if (SclTy->isFloatingPointTy())
|
||||
return ConstantDataVector::getFP(Type::getDoubleTy(Ctx), RawBits);
|
||||
return ConstantDataVector::get(Ctx, RawBits);
|
||||
}
|
||||
|
||||
bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
|
||||
|
||||
@@ -48,7 +48,7 @@ define void @concat_of_broadcast_v2f64_v4f64() {
|
||||
; AVX1-NEXT: movl $1091567616, 30256(%rax) # imm = 0x41100000
|
||||
; AVX1-NEXT: movabsq $4294967297, %rcx # imm = 0x100000001
|
||||
; AVX1-NEXT: movq %rcx, 46348(%rax)
|
||||
; AVX1-NEXT: vbroadcastss {{.*#+}} ymm0 = [1065353216,1065353216,1065353216,1065353216,1065353216,1065353216,1065353216,1065353216]
|
||||
; AVX1-NEXT: vbroadcastss {{.*#+}} ymm0 = [1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0,1.0E+0]
|
||||
; AVX1-NEXT: vmovups %ymm0, 48296(%rax)
|
||||
; AVX1-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
|
||||
; AVX1-NEXT: vmovsd %xmm0, 47372(%rax)
|
||||
|
||||
Reference in New Issue
Block a user