diff options
author | Connor Abbott <[email protected]> | 2017-07-31 18:28:45 -0700 |
---|---|---|
committer | Andres Gomez <[email protected]> | 2017-08-19 13:46:04 +0300 |
commit | 7056362f8dfe2629c901de0b35315aa3aee0aec0 (patch) | |
tree | 0e76fed532d6d250307cca6ad9fd8751a4c64a6a | |
parent | 2766ed0d45b2c3397de5cbdfa9cf7e03a0fdfb5d (diff) |
ac/nir: fix lsb emission
This makes it match radeonsi. The LLVM backend itself will emit the
correct instruction, but LLVM might do incorrect optimizations since it
thinks the output is undefined when the input is 0, even though it's not
supposed to be. We really need a new intrinsic, or for the backend to
become smarter and recognize this pattern.
Cc: [email protected]
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
(cherry picked from commit 6d731c5651ea98551e0bf0c1a8896d5ea63558d5)
[Andres Gomez: nir_to_llvm_context not yet converted into ac_llvm_context]
Signed-off-by: Andres Gomez <[email protected]>
Conflicts:
src/amd/common/ac_nir_to_llvm.c
-rw-r--r-- | src/amd/common/ac_nir_to_llvm.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index 791359aeecd..0c512aa9a24 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -1135,7 +1135,17 @@ static LLVMValueRef emit_find_lsb(struct nir_to_llvm_context *ctx, */ LLVMConstInt(ctx->i32, 1, false), }; - return ac_build_intrinsic(&ctx->ac, "llvm.cttz.i32", ctx->i32, params, 2, AC_FUNC_ATTR_READNONE); + + LLVMValueRef lsb = ac_build_intrinsic(&ctx->ac, "llvm.cttz.i32", ctx->i32, + params, 2, + AC_FUNC_ATTR_READNONE); + + /* TODO: We need an intrinsic to skip this conditional. */ + /* Check for zero: */ + return LLVMBuildSelect(ctx->builder, LLVMBuildICmp(ctx->builder, + LLVMIntEQ, src0, + ctx->i32zero, ""), + LLVMConstInt(ctx->i32, -1, 0), lsb, ""); } static LLVMValueRef emit_ifind_msb(struct nir_to_llvm_context *ctx, |