diff options
author | Tom Stellard <[email protected]> | 2016-04-18 14:33:43 -0400 |
---|---|---|
committer | Tom Stellard <[email protected]> | 2016-04-22 23:48:41 +0000 |
commit | d3427412a335ec64d05e09e040a2ddb2b9552563 (patch) | |
tree | 1fec7031be5d238b839fa533fa0b146042945e78 | |
parent | b31422d970848c4f0925bdd83850393fa3f0ab8c (diff) |
radeonsi: Set range metadata on calls to llvm.SI.tid
The range metadata tells LLVM the range of expected values for this intrinsic,
so it can do some additional optimizations on the result.
Reviewed-by: Michel Dänzer <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
-rw-r--r-- | src/gallium/drivers/radeonsi/si_shader.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index a8749e4ee94..cd6725ecdfc 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -1116,12 +1116,35 @@ static LLVMValueRef get_sample_id(struct radeon_llvm_context *radeon_bld) SI_PARAM_ANCILLARY, 8, 4); } +/** + * Set range metadata on an instruction. This can only be used on load and + * call instructions. If you know an instruction can only produce the values + * 0, 1, 2, you would do set_range_metadata(value, 0, 3); + * \p lo is the minimum value inclusive. + * \p hi is the maximum value exclusive. + */ +static void set_range_metadata(LLVMValueRef value, unsigned lo, unsigned hi) +{ + const char *range_md_string = "range"; + LLVMValueRef range_md, md_args[2]; + LLVMTypeRef type = LLVMTypeOf(value); + LLVMContextRef context = LLVMGetTypeContext(type); + unsigned md_range_id = LLVMGetMDKindIDInContext(context, + range_md_string, strlen(range_md_string)); + + md_args[0] = LLVMConstInt(type, lo, false); + md_args[1] = LLVMConstInt(type, hi, false); + range_md = LLVMMDNodeInContext(context, md_args, 2); + LLVMSetMetadata(value, md_range_id, range_md); +} + static LLVMValueRef get_thread_id(struct si_shader_context *ctx) { struct gallivm_state *gallivm = &ctx->radeon_bld.gallivm; - - return lp_build_intrinsic(gallivm->builder, "llvm.SI.tid", ctx->i32, - NULL, 0, LLVMReadNoneAttribute); + LLVMValueRef tid = lp_build_intrinsic(gallivm->builder, "llvm.SI.tid", + ctx->i32, NULL, 0, LLVMReadNoneAttribute); + set_range_metadata(tid, 0, 64); + return tid; } /** |