[Beignet] [PATCH 1/2] Fix zeroinitializer load/store vector assert.
Yang Rong
rong.r.yang at intel.com
Mon Oct 21 04:12:55 PDT 2013
After move the newValueProxy of vector load/store to genWriter pass, genWriter will
get ConstantAggregateZero of load/store vector with zeroinitializer. In function processConstant,
don't handle correct type of ConstantAggregateZero, cause assert. Add the types handle.
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
backend/src/llvm/llvm_gen_backend.cpp | 53 +++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 12 deletions(-)
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index ea34675..803f797 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -275,6 +275,17 @@ namespace gbe
return ir::MEM_GLOBAL;
}
+ static Constant *extractConstantElem(Constant *CPV, uint32_t index) {
+ ConstantVector *CV = dyn_cast<ConstantVector>(CPV);
+ GBE_ASSERT(CV != NULL);
+#if GBE_DEBUG
+ const uint32_t elemNum = CV->getNumOperands();
+ GBE_ASSERTM(index < elemNum, "Out-of-bound constant vector access");
+#endif /* GBE_DEBUG */
+ CPV = cast<Constant>(CV->getOperand(index));
+ return CPV;
+ }
+
/*! Handle the LLVM IR Value to Gen IR register translation. This has 2 roles:
* - Split the LLVM vector into several scalar values
* - Handle the transparent copies (bitcast or use of intrincics functions
@@ -386,6 +397,8 @@ namespace gbe
getRealValue(value, index);
Constant *CPV = dyn_cast<Constant>(value);
+ if(CPV && dyn_cast<ConstantVector>(CPV))
+ CPV = extractConstantElem(CPV, index);
return (CPV && (isa<UndefValue>(CPV)));
}
private:
@@ -690,17 +703,6 @@ namespace gbe
return false;
}
- static Constant *extractConstantElem(Constant *CPV, uint32_t index) {
- ConstantVector *CV = dyn_cast<ConstantVector>(CPV);
- GBE_ASSERT(CV != NULL);
-#if GBE_DEBUG
- const uint32_t elemNum = CV->getNumOperands();
- GBE_ASSERTM(index < elemNum, "Out-of-bound constant vector access");
-#endif /* GBE_DEBUG */
- CPV = cast<Constant>(CV->getOperand(index));
- return CPV;
- }
-
template <typename U, typename T>
static U processConstant(Constant *CPV, T doIt, uint32_t index = 0u)
{
@@ -741,7 +743,34 @@ namespace gbe
#endif /* LLVM_VERSION_MINOR > 0 */
if (dyn_cast<ConstantAggregateZero>(CPV)) {
- return doIt(uint32_t(0)); // XXX Handle type
+ Type* Ty = CPV->getType();
+ if(Ty->isVectorTy())
+ Ty = (cast<VectorType>(Ty))->getElementType();
+ if (Ty == Type::getInt1Ty(CPV->getContext())) {
+ const bool b = 0;
+ return doIt(b);
+ } else if (Ty == Type::getInt8Ty(CPV->getContext())) {
+ const uint8_t u8 = 0;
+ return doIt(u8);
+ } else if (Ty == Type::getInt16Ty(CPV->getContext())) {
+ const uint16_t u16 = 0;
+ return doIt(u16);
+ } else if (Ty == Type::getInt32Ty(CPV->getContext())) {
+ const uint32_t u32 = 0;
+ return doIt(u32);
+ } else if (Ty == Type::getInt64Ty(CPV->getContext())) {
+ const uint64_t u64 = 0;
+ return doIt(u64);
+ } else if (Ty == Type::getFloatTy(CPV->getContext())) {
+ const float f32 = 0;
+ return doIt(f32);
+ } else if (Ty == Type::getDoubleTy(CPV->getContext())) {
+ const float f64 = 0;
+ return doIt(f64);
+ } else {
+ GBE_ASSERTM(false, "Unsupporte aggregate zero type.");
+ return doIt(uint32_t(0));
+ }
} else {
if (dyn_cast<ConstantVector>(CPV))
CPV = extractConstantElem(CPV, index);
--
1.8.1.2
More information about the Beignet
mailing list