Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions llvm/lib/Target/DirectX/DXILDataScalarization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,14 @@ static Constant *transformInitializer(Constant *Init, Type *OrigType,
if (isa<VectorType>(OrigType) && isa<ArrayType>(NewType)) {
// Convert vector initializer to array initializer
SmallVector<Constant *, MaxVecSize> ArrayElements;
if (ConstantVector *ConstVecInit = dyn_cast<ConstantVector>(Init)) {
for (unsigned I = 0; I < ConstVecInit->getNumOperands(); ++I)
ArrayElements.push_back(ConstVecInit->getOperand(I));
} else if (ConstantDataVector *ConstDataVecInit =
llvm::dyn_cast<llvm::ConstantDataVector>(Init)) {
for (unsigned I = 0; I < ConstDataVecInit->getNumElements(); ++I)
ArrayElements.push_back(ConstDataVecInit->getElementAsConstant(I));
} else {
assert(false && "Expected a ConstantVector or ConstantDataVector for "
"vector initializer!");
}

unsigned E = cast<FixedVectorType>(OrigType)->getNumElements();
for (unsigned I = 0; I != E; ++I)
if (Constant *Elt = Init->getAggregateElement(I))
ArrayElements.push_back(Elt);

assert(ArrayElements.size() == E &&
"Expected fixed length constant aggregate for vector initializer!");
return ConstantArray::get(cast<ArrayType>(NewType), ArrayElements);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
}
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
Code = bitc::CST_CODE_FLOAT;
Type *Ty = CFP->getType();
Type *Ty = CFP->getType()->getScalarType();
if (Ty->isHalfTy() || Ty->isFloatTy() || Ty->isDoubleTy()) {
Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
} else if (Ty->isX86_FP80Ty()) {
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/DirectX/scalar-bug-117273.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes='dxil-data-scalarization,dxil-flatten-arrays,function(scalarizer<load-store>),dxil-op-lower' -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
; RUN: opt -S -passes='dxil-data-scalarization,dxil-flatten-arrays,function(scalarizer<load-store>),dxil-op-lower' -mtriple=dxil-pc-shadermodel6.3-library -use-constant-fp-for-fixed-length-splat %s | FileCheck %s


@StaticArr = internal constant [8 x <3 x float>] [<3 x float> zeroinitializer, <3 x float> splat (float 5.000000e-01), <3 x float> <float 1.000000e+00, float 5.000000e-01, float 5.000000e-01>, <3 x float> <float 5.000000e-01, float 1.000000e+00, float 5.000000e-01>, <3 x float> <float 5.000000e-01, float 5.000000e-01, float 1.000000e+00>, <3 x float> <float 5.000000e-01, float 1.000000e+00, float 1.000000e+00>, <3 x float> <float 1.000000e+00, float 5.000000e-01, float 1.000000e+00>, <3 x float> <float 1.000000e+00, float 1.000000e+00, float 5.000000e-01>], align 16
Expand Down