gallivm: asst. clean-ups in lp_bld_logic.

Signed-off-by: Brian Paul <brianp@vmware.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17064>
This commit is contained in:
Brian Paul 2022-06-09 11:44:03 -06:00 committed by Marge Bot
parent eef5e6ac7c
commit c5521d5af1

View file

@ -62,7 +62,7 @@
* sext <4 x i1> %C to <4 x i32>
*
* is valid and supported (e.g., llvm/test/CodeGen/X86/vec_compare.ll), but
* it causes assertion failures in LLVM 2.6. It appears to work correctly on
* it causes assertion failures in LLVM 2.6. It appears to work correctly on
* LLVM 2.7.
*/
@ -92,15 +92,15 @@ lp_build_compare_ext(struct gallivm_state *gallivm,
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
if(func == PIPE_FUNC_NEVER)
if (func == PIPE_FUNC_NEVER)
return zeros;
if(func == PIPE_FUNC_ALWAYS)
if (func == PIPE_FUNC_ALWAYS)
return ones;
assert(func > PIPE_FUNC_NEVER);
assert(func < PIPE_FUNC_ALWAYS);
if(type.floating) {
if (type.floating) {
LLVMRealPredicate op;
switch(func) {
case PIPE_FUNC_EQUAL:
@ -181,9 +181,9 @@ lp_build_compare(struct gallivm_state *gallivm,
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
if(func == PIPE_FUNC_NEVER)
if (func == PIPE_FUNC_NEVER)
return zeros;
if(func == PIPE_FUNC_ALWAYS)
if (func == PIPE_FUNC_ALWAYS)
return ones;
assert(func > PIPE_FUNC_NEVER);
@ -266,7 +266,7 @@ lp_build_select_bitwise(struct lp_build_context *bld,
return a;
}
if(type.floating) {
if (type.floating) {
a = LLVMBuildBitCast(builder, a, int_vec_type, "");
b = LLVMBuildBitCast(builder, b, int_vec_type, "");
}
@ -284,7 +284,7 @@ lp_build_select_bitwise(struct lp_build_context *bld,
res = LLVMBuildOr(builder, a, b, "");
if(type.floating) {
if (type.floating) {
LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
res = LLVMBuildBitCast(builder, res, vec_type, "");
}
@ -313,7 +313,7 @@ lp_build_select(struct lp_build_context *bld,
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
if(a == b)
if (a == b)
return a;
if (type.length == 1) {
@ -339,11 +339,13 @@ lp_build_select(struct lp_build_context *bld,
* what really happens is that LLVM will emit two shifts back to back.
*/
if (0) {
LLVMValueRef shift = LLVMConstInt(bld->int_elem_type, bld->type.width - 1, 0);
LLVMValueRef shift =
LLVMConstInt(bld->int_elem_type, bld->type.width - 1, 0);
shift = lp_build_broadcast(bld->gallivm, bld->int_vec_type, shift);
mask = LLVMBuildLShr(builder, mask, shift, "");
}
LLVMTypeRef bool_vec_type = LLVMVectorType(LLVMInt1TypeInContext(lc), type.length);
LLVMTypeRef bool_vec_type =
LLVMVectorType(LLVMInt1TypeInContext(lc), type.length);
mask = LLVMBuildTrunc(builder, mask, bool_vec_type, "");
res = LLVMBuildSelect(builder, mask, a, b, "");
@ -363,7 +365,8 @@ lp_build_select(struct lp_build_context *bld,
LLVMTypeRef mask_type = LLVMGetElementType(LLVMTypeOf(mask));
if (LLVMGetIntTypeWidth(mask_type) != type.width) {
LLVMTypeRef int_vec_type = LLVMVectorType(LLVMIntTypeInContext(lc, type.width), type.length);
LLVMTypeRef int_vec_type =
LLVMVectorType(LLVMIntTypeInContext(lc, type.width), type.length);
mask = LLVMBuildSExt(builder, mask, int_vec_type, "");
}
/*
@ -440,19 +443,18 @@ lp_build_select_aos(struct lp_build_context *bld,
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
assert((mask & ~0xf) == 0);
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
if(a == b)
if (a == b)
return a;
if((mask & 0xf) == 0xf)
if ((mask & 0xf) == 0xf)
return a;
if((mask & 0xf) == 0x0)
if ((mask & 0xf) == 0x0)
return b;
if(a == bld->undef || b == bld->undef)
if (a == bld->undef || b == bld->undef)
return bld->undef;
/*
@ -469,16 +471,18 @@ lp_build_select_aos(struct lp_build_context *bld,
LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += num_channels)
for(i = 0; i < num_channels; ++i)
for (unsigned j = 0; j < n; j += num_channels)
for (unsigned i = 0; i < num_channels; ++i)
shuffles[j + i] = LLVMConstInt(elem_type,
(mask & (1 << i) ? 0 : n) + j + i,
0);
return LLVMBuildShuffleVector(builder, a, b, LLVMConstVector(shuffles, n), "");
return LLVMBuildShuffleVector(builder, a, b,
LLVMConstVector(shuffles, n), "");
}
else {
LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask, num_channels);
LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm,
type, mask, num_channels);
return lp_build_select(bld, mask_vec, a, b);
}
}