gallivm: Use a more compact approach for lp_build_broadcast_scalar().
It produces exactly the same machine code, but it cuts 5% of the number of instructions generated for a typical shader. Also, preserve the scalar when length is 1.
This commit is contained in:
@@ -68,18 +68,20 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
|
|||||||
LLVMValueRef scalar)
|
LLVMValueRef scalar)
|
||||||
{
|
{
|
||||||
const struct lp_type type = bld->type;
|
const struct lp_type type = bld->type;
|
||||||
LLVMValueRef res;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
assert(lp_check_elem_type(type, LLVMTypeOf(scalar)));
|
assert(lp_check_elem_type(type, LLVMTypeOf(scalar)));
|
||||||
|
|
||||||
res = bld->undef;
|
if (type.length == 1) {
|
||||||
for(i = 0; i < type.length; ++i) {
|
return scalar;
|
||||||
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
|
}
|
||||||
res = LLVMBuildInsertElement(bld->builder, res, scalar, index, "");
|
else {
|
||||||
|
LLVMValueRef res;
|
||||||
|
res = LLVMBuildInsertElement(bld->builder, bld->undef, scalar,
|
||||||
|
LLVMConstInt(LLVMInt32Type(), 0, 0), "");
|
||||||
|
res = LLVMBuildShuffleVector(bld->builder, res, bld->undef,
|
||||||
|
lp_build_const_int_vec(type, 0), "");
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user