Module: Mesa
Branch: master
Commit: 3d41757788aca774e64297bed962696cc0c9b262
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3d41757788aca774e64297bed962696cc0c9b262

Author: Samuel Pitoiset <[email protected]>
Date:   Thu Jul 19 20:27:11 2018 +0200

ac/nir: add a workaround for bitfield_extract when count is 0

LLVM 7 returns incorrect results when count is 0, something
has been broken since LLVM 6. Of course, the best solution is
to fix LLVM but this workaround works as expected for now.

Original workaround by Philippe Rebohle.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107276
Signed-off-by: Samuel Pitoiset <[email protected]>
Reviewed-by: Bas Nieuwenhuizen <[email protected]>

---

 src/amd/common/ac_nir_to_llvm.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 83d8b9a442..10d1773850 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -418,10 +418,24 @@ static LLVMValueRef emit_bitfield_extract(struct 
ac_llvm_context *ctx,
                                          const LLVMValueRef srcs[3])
 {
        LLVMValueRef result;
-       LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], 
LLVMConstInt(ctx->i32, 32, false), "");
 
-       result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], is_signed);
-       result = LLVMBuildSelect(ctx->builder, icond, srcs[0], result, "");
+       if (HAVE_LLVM < 0x0700) {
+               LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, 
srcs[2], LLVMConstInt(ctx->i32, 32, false), "");
+               result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], 
is_signed);
+               result = LLVMBuildSelect(ctx->builder, icond, srcs[0], result, 
"");
+       } else {
+               /* FIXME: LLVM 7 returns incorrect result when count is 0.
+                * https://bugs.freedesktop.org/show_bug.cgi?id=107276
+                */
+               LLVMValueRef zero = LLVMConstInt(ctx->i32, 0, false);
+               LLVMValueRef icond1 = LLVMBuildICmp(ctx->builder, LLVMIntEQ, 
srcs[2], LLVMConstInt(ctx->i32, 32, false), "");
+               LLVMValueRef icond2 = LLVMBuildICmp(ctx->builder, LLVMIntEQ, 
srcs[2], zero, "");
+
+               result = ac_build_bfe(ctx, srcs[0], srcs[1], srcs[2], 
is_signed);
+               result = LLVMBuildSelect(ctx->builder, icond1, srcs[0], result, 
"");
+               result = LLVMBuildSelect(ctx->builder, icond2, zero, result, 
"");
+       }
+
        return result;
 }
 

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to