Skip to content

Commit 8d5b06a

Browse files
[LLVM][AsmPrinter] Add vector ConstantInt/FP support to emitGlobalConstantImpl.
1 parent 02328e0 commit 8d5b06a

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,10 +3602,11 @@ static void emitGlobalConstantArray(const DataLayout &DL,
36023602

36033603
static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP);
36043604

3605-
static void emitGlobalConstantVector(const DataLayout &DL,
3606-
const ConstantVector *CV, AsmPrinter &AP,
3605+
static void emitGlobalConstantVector(const DataLayout &DL, const Constant *CV,
3606+
AsmPrinter &AP,
36073607
AsmPrinter::AliasMapTy *AliasList) {
3608-
Type *ElementType = CV->getType()->getElementType();
3608+
auto *VTy = cast<FixedVectorType>(CV->getType());
3609+
Type *ElementType = VTy->getElementType();
36093610
uint64_t ElementSizeInBits = DL.getTypeSizeInBits(ElementType);
36103611
uint64_t ElementAllocSizeInBits = DL.getTypeAllocSizeInBits(ElementType);
36113612
uint64_t EmittedSize;
@@ -3618,7 +3619,7 @@ static void emitGlobalConstantVector(const DataLayout &DL,
36183619
Type *IntT =
36193620
IntegerType::get(CV->getContext(), DL.getTypeSizeInBits(CV->getType()));
36203621
ConstantInt *CI = dyn_cast_or_null<ConstantInt>(ConstantFoldConstant(
3621-
ConstantExpr::getBitCast(const_cast<ConstantVector *>(CV), IntT), DL));
3622+
ConstantExpr::getBitCast(const_cast<Constant *>(CV), IntT), DL));
36223623
if (!CI) {
36233624
report_fatal_error(
36243625
"Cannot lower vector global with unusual element type");
@@ -3627,12 +3628,11 @@ static void emitGlobalConstantVector(const DataLayout &DL,
36273628
emitGlobalConstantLargeInt(CI, AP);
36283629
EmittedSize = DL.getTypeStoreSize(CV->getType());
36293630
} else {
3630-
for (unsigned I = 0, E = CV->getType()->getNumElements(); I != E; ++I) {
3631+
for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) {
36313632
emitGlobalAliasInline(AP, DL.getTypeAllocSize(CV->getType()) * I, AliasList);
3632-
emitGlobalConstantImpl(DL, CV->getOperand(I), AP);
3633+
emitGlobalConstantImpl(DL, CV->getAggregateElement(I), AP);
36333634
}
3634-
EmittedSize =
3635-
DL.getTypeAllocSize(ElementType) * CV->getType()->getNumElements();
3635+
EmittedSize = DL.getTypeAllocSize(ElementType) * VTy->getNumElements();
36363636
}
36373637

36383638
unsigned Size = DL.getTypeAllocSize(CV->getType());
@@ -3902,8 +3902,10 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
39023902
return AP.OutStreamer->emitZeros(Size);
39033903

39043904
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
3905-
const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType());
3905+
if (isa<VectorType>(CV->getType()))
3906+
return emitGlobalConstantVector(DL, CV, AP, AliasList);
39063907

3908+
const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType());
39073909
if (StoreSize <= 8) {
39083910
if (AP.isVerbose())
39093911
AP.OutStreamer->getCommentOS()
@@ -3920,8 +3922,12 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
39203922
return;
39213923
}
39223924

3923-
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
3924-
return emitGlobalConstantFP(CFP, AP);
3925+
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
3926+
if (isa<VectorType>(CV->getType()))
3927+
return emitGlobalConstantVector(DL, CV, AP, AliasList);
3928+
else
3929+
return emitGlobalConstantFP(CFP, AP);
3930+
}
39253931

39263932
if (isa<ConstantPointerNull>(CV)) {
39273933
AP.OutStreamer->emitIntValue(0, Size);
@@ -3953,8 +3959,8 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
39533959
}
39543960
}
39553961

3956-
if (const ConstantVector *V = dyn_cast<ConstantVector>(CV))
3957-
return emitGlobalConstantVector(DL, V, AP, AliasList);
3962+
if (isa<ConstantVector>(CV))
3963+
return emitGlobalConstantVector(DL, CV, AP, AliasList);
39583964

39593965
// Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it
39603966
// thread the streamer with EmitValue.

llvm/lib/IR/Constants.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ Constant *Constant::getAggregateElement(unsigned Elt) const {
451451
? ConstantInt::get(getContext(), CI->getValue())
452452
: nullptr;
453453

454+
if (const auto *CFP = dyn_cast<ConstantFP>(this))
455+
return Elt < cast<VectorType>(getType())
456+
->getElementCount()
457+
.getKnownMinValue()
458+
? ConstantFP::get(getContext(), CFP->getValue())
459+
: nullptr;
460+
454461
// FIXME: getNumElements() will fail for non-fixed vector types.
455462
if (isa<ScalableVectorType>(getType()))
456463
return nullptr;

llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-splat-vector.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc -mattr=+sve -force-streaming-compatible < %s | FileCheck %s
33
; RUN: llc -force-streaming-compatible < %s | FileCheck %s --check-prefix=NONEON-NOSVE
4-
5-
4+
; RUN: llc -force-streaming-compatible -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat < %s | FileCheck %s --check-prefix=NONEON-NOSVE
65

76
target triple = "aarch64-unknown-linux-gnu"
87

0 commit comments

Comments
 (0)