Fix bug with constant folding of select expressions.
We would sometimes pass an int32_t * to the ConstExpr constructor but claim the underlying type was uint32, which made it grumpy.
This commit is contained in:
26
expr.cpp
26
expr.cpp
@@ -3195,8 +3195,9 @@ SelectExpr::Optimize() {
|
||||
AssertPos(pos, exprType->IsVaryingType());
|
||||
|
||||
// FIXME: it's annoying to have to have all of this replicated code.
|
||||
if (Type::Equal(exprType, AtomicType::VaryingInt32) ||
|
||||
Type::Equal(exprType, AtomicType::VaryingUInt32)) {
|
||||
// FIXME: for completeness, it would also be nice to handle 8 and
|
||||
// 16 bit types...
|
||||
if (Type::Equal(exprType, AtomicType::VaryingInt32)) {
|
||||
int32_t v1[ISPC_MAX_NVEC], v2[ISPC_MAX_NVEC];
|
||||
int32_t result[ISPC_MAX_NVEC];
|
||||
constExpr1->AsInt32(v1);
|
||||
@@ -3205,8 +3206,16 @@ SelectExpr::Optimize() {
|
||||
result[i] = bv[i] ? v1[i] : v2[i];
|
||||
return new ConstExpr(exprType, result, pos);
|
||||
}
|
||||
else if (Type::Equal(exprType, AtomicType::VaryingInt64) ||
|
||||
Type::Equal(exprType, AtomicType::VaryingUInt64)) {
|
||||
if (Type::Equal(exprType, AtomicType::VaryingUInt32)) {
|
||||
uint32_t v1[ISPC_MAX_NVEC], v2[ISPC_MAX_NVEC];
|
||||
uint32_t result[ISPC_MAX_NVEC];
|
||||
constExpr1->AsUInt32(v1);
|
||||
constExpr2->AsUInt32(v2);
|
||||
for (int i = 0; i < count; ++i)
|
||||
result[i] = bv[i] ? v1[i] : v2[i];
|
||||
return new ConstExpr(exprType, result, pos);
|
||||
}
|
||||
else if (Type::Equal(exprType, AtomicType::VaryingInt64)) {
|
||||
int64_t v1[ISPC_MAX_NVEC], v2[ISPC_MAX_NVEC];
|
||||
int64_t result[ISPC_MAX_NVEC];
|
||||
constExpr1->AsInt64(v1);
|
||||
@@ -3215,6 +3224,15 @@ SelectExpr::Optimize() {
|
||||
result[i] = bv[i] ? v1[i] : v2[i];
|
||||
return new ConstExpr(exprType, result, pos);
|
||||
}
|
||||
else if (Type::Equal(exprType, AtomicType::VaryingUInt64)) {
|
||||
uint64_t v1[ISPC_MAX_NVEC], v2[ISPC_MAX_NVEC];
|
||||
uint64_t result[ISPC_MAX_NVEC];
|
||||
constExpr1->AsUInt64(v1);
|
||||
constExpr2->AsUInt64(v2);
|
||||
for (int i = 0; i < count; ++i)
|
||||
result[i] = bv[i] ? v1[i] : v2[i];
|
||||
return new ConstExpr(exprType, result, pos);
|
||||
}
|
||||
else if (Type::Equal(exprType, AtomicType::VaryingFloat)) {
|
||||
float v1[ISPC_MAX_NVEC], v2[ISPC_MAX_NVEC];
|
||||
float result[ISPC_MAX_NVEC];
|
||||
|
||||
Reference in New Issue
Block a user