diff options
author | Nicolai Hähnle <[email protected]> | 2017-06-25 13:04:51 +0200 |
---|---|---|
committer | Nicolai Hähnle <[email protected]> | 2017-07-31 14:55:42 +0200 |
commit | ac2ab5acadb9b792b41e0cdb3c59b8edb6dde64b (patch) | |
tree | e77e2e28827b6ebbc46223abc7371517a90aadc7 /src | |
parent | e247357240f4d429f954b5019852053683b6dd1c (diff) |
ac/nir: add always_vector argument to ac_build_gather_values_extended
This simplifies a bunch of places that no longer need special treatment
of value_count == 1. We rely on LLVM to optimize away the 1-element vector
types.
This fixes a bunch of bugs where 1-element arrays are indexed indirectly.
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/amd/common/ac_llvm_build.c | 7 | ||||
-rw-r--r-- | src/amd/common/ac_llvm_build.h | 3 | ||||
-rw-r--r-- | src/amd/common/ac_nir_to_llvm.c | 22 |
3 files changed, 13 insertions, 19 deletions
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index 2cc4eaee224..2dddf44ff85 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -181,13 +181,14 @@ ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values, unsigned value_count, unsigned value_stride, - bool load) + bool load, + bool always_vector) { LLVMBuilderRef builder = ctx->builder; LLVMValueRef vec = NULL; unsigned i; - if (value_count == 1) { + if (value_count == 1 && !always_vector) { if (load) return LLVMBuildLoad(builder, values[0], ""); return values[0]; @@ -212,7 +213,7 @@ ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values, unsigned value_count) { - return ac_build_gather_values_extended(ctx, values, value_count, 1, false); + return ac_build_gather_values_extended(ctx, values, value_count, 1, false, false); } LLVMValueRef diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h index 10efabbab95..f25af8b76a8 100644 --- a/src/amd/common/ac_llvm_build.h +++ b/src/amd/common/ac_llvm_build.h @@ -78,7 +78,8 @@ ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values, unsigned value_count, unsigned value_stride, - bool load); + bool load, + bool always_vector); LLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values, diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index a089d69a843..f75d8958fcc 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -1017,11 +1017,6 @@ build_store_values_extended(struct ac_llvm_context *ac, LLVMBuilderRef builder = ac->builder; unsigned i; - if (value_count == 1) { - LLVMBuildStore(builder, vec, values[0]); - return; - } - for (i = 0; i < value_count; i++) { LLVMValueRef ptr = values[i * value_stride]; LLVMValueRef index = LLVMConstInt(ac->i32, i, false); @@ -2986,7 +2981,7 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx, count -= chan / 4; LLVMValueRef tmp_vec = ac_build_gather_values_extended( &ctx->ac, ctx->abi->inputs + idx + chan, count, - 4, false); + 4, false, true); values[chan] = LLVMBuildExtractElement(ctx->ac.builder, tmp_vec, @@ -3003,7 +2998,7 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx, count -= chan / 4; LLVMValueRef tmp_vec = ac_build_gather_values_extended( &ctx->ac, ctx->locals + idx + chan, count, - 4, true); + 4, true, true); values[chan] = LLVMBuildExtractElement(ctx->ac.builder, tmp_vec, @@ -3031,7 +3026,7 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx, count -= chan / 4; LLVMValueRef tmp_vec = ac_build_gather_values_extended( &ctx->ac, ctx->outputs + idx + chan, count, - 4, true); + 4, true, true); values[chan] = LLVMBuildExtractElement(ctx->ac.builder, tmp_vec, @@ -3100,13 +3095,10 @@ visit_store_var(struct ac_nir_context *ctx, count -= chan / 4; LLVMValueRef tmp_vec = ac_build_gather_values_extended( &ctx->ac, ctx->outputs + idx + chan, count, - stride, true); + stride, true, true); - if (get_llvm_num_components(tmp_vec) > 1) { - tmp_vec = LLVMBuildInsertElement(ctx->ac.builder, tmp_vec, - value, indir_index, ""); - } else - tmp_vec = value; + tmp_vec = LLVMBuildInsertElement(ctx->ac.builder, tmp_vec, + value, indir_index, ""); build_store_values_extended(&ctx->ac, ctx->outputs + idx + chan, count, stride, tmp_vec); @@ -3129,7 +3121,7 @@ visit_store_var(struct ac_nir_context *ctx, count -= chan / 4; LLVMValueRef tmp_vec = ac_build_gather_values_extended( &ctx->ac, ctx->locals + idx + chan, count, - 4, true); + 4, true, true); tmp_vec = LLVMBuildInsertElement(ctx->ac.builder, tmp_vec, value, indir_index, ""); |