Skip to content

Commit

Permalink
[clang codegen] Clean up handling of vectors with trivial-auto-var-init.
Browse files Browse the repository at this point in the history
The code was pretending to be doing something useful with vectors, but
really it was doing nothing: the element type of a vector is always a
scalar type, so constWithPadding would always just return the input constant.

Split off from D75661 so it can be reviewed separately.

While I'm here, also add testcase to show missing vector handling.

Differential Revision: https://reviews.llvm.org/D76528
  • Loading branch information
efriedma-quic committed Mar 24, 2020
1 parent 4f4e687 commit 3f1defa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
17 changes: 7 additions & 10 deletions clang/lib/CodeGen/CGDecl.cpp
Expand Up @@ -1050,13 +1050,13 @@ static llvm::Constant *constWithPadding(CodeGenModule &CGM, IsPattern isPattern,
llvm::Type *OrigTy = constant->getType();
if (const auto STy = dyn_cast<llvm::StructType>(OrigTy))
return constStructWithPadding(CGM, isPattern, STy, constant);
if (auto *STy = dyn_cast<llvm::SequentialType>(OrigTy)) {
if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(OrigTy)) {
llvm::SmallVector<llvm::Constant *, 8> Values;
unsigned Size = STy->getNumElements();
uint64_t Size = ArrayTy->getNumElements();
if (!Size)
return constant;
llvm::Type *ElemTy = STy->getElementType();
bool ZeroInitializer = constant->isZeroValue();
llvm::Type *ElemTy = ArrayTy->getElementType();
bool ZeroInitializer = constant->isNullValue();
llvm::Constant *OpValue, *PaddedOp;
if (ZeroInitializer) {
OpValue = llvm::Constant::getNullValue(ElemTy);
Expand All @@ -1072,13 +1072,10 @@ static llvm::Constant *constWithPadding(CodeGenModule &CGM, IsPattern isPattern,
auto *NewElemTy = Values[0]->getType();
if (NewElemTy == ElemTy)
return constant;
if (OrigTy->isArrayTy()) {
auto *ArrayTy = llvm::ArrayType::get(NewElemTy, Size);
return llvm::ConstantArray::get(ArrayTy, Values);
} else {
return llvm::ConstantVector::get(Values);
}
auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size);
return llvm::ConstantArray::get(NewArrayTy, Values);
}
// FIXME: Do we need to handle tail padding in vectors?
return constant;
}

Expand Down
19 changes: 19 additions & 0 deletions clang/test/CodeGenCXX/auto-var-init.cpp
Expand Up @@ -1610,5 +1610,24 @@ TEST_CUSTOM(doublevec32, double __attribute__((vector_size(32))), { 3.141592653
// CHECK-NEXT: store <4 x double> <double 0x400921FB54442D18, double 0x400921FB54442D18, double 0x400921FB54442D18, double 0x400921FB54442D18>, <4 x double>* %custom, align [[ALIGN]]
// CHECK-NEXT: call void @{{.*}}used{{.*}}%custom)

// TODO: This vector has tail padding
TEST_UNINIT(doublevec24, double __attribute__((vector_size(24))));
// CHECK-LABEL: @test_doublevec24_uninit()
// CHECK: %uninit = alloca <3 x double>, align
// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit)
// PATTERN-LABEL: @test_doublevec24_uninit()
// PATTERN: store <3 x double> <double 0xFFFFFFFFFFFFFFFF, double 0xFFFFFFFFFFFFFFFF, double 0xFFFFFFFFFFFFFFFF>, <3 x double>* %uninit, align 32
// ZERO-LABEL: @test_doublevec24_uninit()
// ZERO: store <3 x double> zeroinitializer, <3 x double>* %uninit, align 32

// TODO: This vector has tail padding
TEST_UNINIT(longdoublevec32, long double __attribute__((vector_size(sizeof(long double)*2))));
// CHECK-LABEL: @test_longdoublevec32_uninit()
// CHECK: %uninit = alloca <2 x x86_fp80>, align
// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit)
// PATTERN-LABEL: @test_longdoublevec32_uninit()
// PATTERN: store <2 x x86_fp80> <x86_fp80 0xKFFFFFFFFFFFFFFFFFFFF, x86_fp80 0xKFFFFFFFFFFFFFFFFFFFF>, <2 x x86_fp80>* %uninit, align 32
// ZERO-LABEL: @test_longdoublevec32_uninit()
// ZERO: store <2 x x86_fp80> zeroinitializer, <2 x x86_fp80>* %uninit, align 32

} // extern "C"

0 comments on commit 3f1defa

Please sign in to comment.