Skip to content

Commit 33819f3

Browse files
committed
[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.
1 parent a7d8d11 commit 33819f3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

llvm/lib/Target/X86/X86FixupVectorConstants.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ static Constant *rebuildSplatableConstant(const Constant *C,
190190
Type *SclTy = OriginalType->getScalarType();
191191
unsigned NumSclBits = SclTy->getPrimitiveSizeInBits();
192192
NumSclBits = std::min<unsigned>(NumSclBits, SplatBitWidth);
193+
LLVMContext &Ctx = OriginalType->getContext();
193194

194195
if (NumSclBits == 8) {
195196
SmallVector<uint8_t> RawBits;
196197
for (unsigned I = 0; I != SplatBitWidth; I += 8)
197198
RawBits.push_back(Splat->extractBits(8, I).getZExtValue());
198-
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
199+
return ConstantDataVector::get(Ctx, RawBits);
199200
}
200201

201202
if (NumSclBits == 16) {
@@ -204,25 +205,25 @@ static Constant *rebuildSplatableConstant(const Constant *C,
204205
RawBits.push_back(Splat->extractBits(16, I).getZExtValue());
205206
if (SclTy->is16bitFPTy())
206207
return ConstantDataVector::getFP(SclTy, RawBits);
207-
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
208+
return ConstantDataVector::get(Ctx, RawBits);
208209
}
209210

210211
if (NumSclBits == 32) {
211212
SmallVector<uint32_t> RawBits;
212213
for (unsigned I = 0; I != SplatBitWidth; I += 32)
213214
RawBits.push_back(Splat->extractBits(32, I).getZExtValue());
214-
if (SclTy->isFloatTy())
215-
return ConstantDataVector::getFP(SclTy, RawBits);
216-
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
215+
if (SclTy->isFloatingPointTy())
216+
return ConstantDataVector::getFP(Type::getFloatTy(Ctx), RawBits);
217+
return ConstantDataVector::get(Ctx, RawBits);
217218
}
218219

219220
// Fallback to i64 / double.
220221
SmallVector<uint64_t> RawBits;
221222
for (unsigned I = 0; I != SplatBitWidth; I += 64)
222223
RawBits.push_back(Splat->extractBits(64, I).getZExtValue());
223-
if (SclTy->isDoubleTy())
224-
return ConstantDataVector::getFP(SclTy, RawBits);
225-
return ConstantDataVector::get(OriginalType->getContext(), RawBits);
224+
if (SclTy->isFloatingPointTy())
225+
return ConstantDataVector::getFP(Type::getDoubleTy(Ctx), RawBits);
226+
return ConstantDataVector::get(Ctx, RawBits);
226227
}
227228

228229
bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,

llvm/test/CodeGen/X86/combine-concatvectors.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define void @concat_of_broadcast_v2f64_v4f64() {
4848
; AVX1-NEXT: movl $1091567616, 30256(%rax) # imm = 0x41100000
4949
; AVX1-NEXT: movabsq $4294967297, %rcx # imm = 0x100000001
5050
; AVX1-NEXT: movq %rcx, 46348(%rax)
51-
; AVX1-NEXT: vbroadcastss {{.*#+}} ymm0 = [1065353216,1065353216,1065353216,1065353216,1065353216,1065353216,1065353216,1065353216]
51+
; 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]
5252
; AVX1-NEXT: vmovups %ymm0, 48296(%rax)
5353
; AVX1-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
5454
; AVX1-NEXT: vmovsd %xmm0, 47372(%rax)

0 commit comments

Comments
 (0)