From d6b8026ad5cc41b6cbaacfd8a9a34592cffa2ea2 Mon Sep 17 00:00:00 2001 From: listerily Date: Mon, 15 May 2023 13:14:17 +0800 Subject: [PATCH 1/2] [llvm] Simplified and add support for type u1 in logical not operation [ghstack-poisoned] --- taichi/codegen/amdgpu/codegen_amdgpu.cpp | 8 +------- taichi/codegen/cuda/codegen_cuda.cpp | 6 ------ taichi/codegen/llvm/codegen_llvm.cpp | 7 ++++++- taichi/runtime/llvm/runtime_module/runtime.cpp | 4 ---- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/taichi/codegen/amdgpu/codegen_amdgpu.cpp b/taichi/codegen/amdgpu/codegen_amdgpu.cpp index 9d4f4ac10b39f..5b2431ef54eb5 100644 --- a/taichi/codegen/amdgpu/codegen_amdgpu.cpp +++ b/taichi/codegen/amdgpu/codegen_amdgpu.cpp @@ -65,13 +65,7 @@ class TaskCodeGenAMDGPU : public TaskCodeGenLLVM { TI_NOT_IMPLEMENTED \ } \ } - if (op == UnaryOpType::logic_not) { - if (input_taichi_type->is_primitive(PrimitiveTypeID::i32)) { - llvm_val[stmt] = call("logic_not_i32", input); - } else { - TI_NOT_IMPLEMENTED - } - } else if (op == UnaryOpType::abs) { + if (op == UnaryOpType::abs) { if (input_taichi_type->is_primitive(PrimitiveTypeID::f16)) { llvm_val[stmt] = call("__ocml_fasb_f16", input); } else if (input_taichi_type->is_primitive(PrimitiveTypeID::f32)) { diff --git a/taichi/codegen/cuda/codegen_cuda.cpp b/taichi/codegen/cuda/codegen_cuda.cpp index dd5b821675908..b39586b3b446a 100644 --- a/taichi/codegen/cuda/codegen_cuda.cpp +++ b/taichi/codegen/cuda/codegen_cuda.cpp @@ -257,12 +257,6 @@ class TaskCodeGenCUDA : public TaskCodeGenLLVM { } else { TI_NOT_IMPLEMENTED } - } else if (op == UnaryOpType::logic_not) { - if (input_taichi_type->is_primitive(PrimitiveTypeID::i32)) { - llvm_val[stmt] = call("logic_not_i32", input); - } else { - TI_NOT_IMPLEMENTED - } } else if (op == UnaryOpType::frexp) { auto stype = tlctx->get_data_type(stmt->ret_type.ptr_removed()); auto res = builder->CreateAlloca(stype); diff --git a/taichi/codegen/llvm/codegen_llvm.cpp b/taichi/codegen/llvm/codegen_llvm.cpp index 30cd0f5aa382f..81f43bd72b645 100644 --- a/taichi/codegen/llvm/codegen_llvm.cpp +++ b/taichi/codegen/llvm/codegen_llvm.cpp @@ -197,7 +197,6 @@ void TaskCodeGenLLVM::emit_extra_unary(UnaryOpStmt *stmt) { UNARY_STD(tan) UNARY_STD(tanh) UNARY_STD(sgn) - UNARY_STD(logic_not) UNARY_STD(acos) UNARY_STD(asin) UNARY_STD(cos) @@ -210,6 +209,12 @@ void TaskCodeGenLLVM::emit_extra_unary(UnaryOpStmt *stmt) { llvm_val[stmt] = builder->CreateIntrinsic(llvm::Intrinsic::ctpop, {input_type}, {input}); } + else if (op == UnaryOpType::logic_not) { + llvm_val[stmt] = builder->CreateSelect( + builder->CreateIsNull(input), + tlctx->get_constant(true), + tlctx->get_constant(false)); + } else { TI_P(unary_op_type_name(op)); TI_NOT_IMPLEMENTED diff --git a/taichi/runtime/llvm/runtime_module/runtime.cpp b/taichi/runtime/llvm/runtime_module/runtime.cpp index 460beb145e7e7..53547922a2e85 100644 --- a/taichi/runtime/llvm/runtime_module/runtime.cpp +++ b/taichi/runtime/llvm/runtime_module/runtime.cpp @@ -229,10 +229,6 @@ i64 max_i64(i64 a, i64 b) { return a > b ? a : b; } -int32 logic_not_i32(int32 a) { - return !a; -} - float32 sgn_f32(float32 a) { float32 b; if (a > 0) From 609bd311c1c51a2a7946f4c64790902dbad12f58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 May 2023 05:15:24 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/codegen/llvm/codegen_llvm.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/taichi/codegen/llvm/codegen_llvm.cpp b/taichi/codegen/llvm/codegen_llvm.cpp index 81f43bd72b645..d649e83b4f6b8 100644 --- a/taichi/codegen/llvm/codegen_llvm.cpp +++ b/taichi/codegen/llvm/codegen_llvm.cpp @@ -210,10 +210,9 @@ void TaskCodeGenLLVM::emit_extra_unary(UnaryOpStmt *stmt) { builder->CreateIntrinsic(llvm::Intrinsic::ctpop, {input_type}, {input}); } else if (op == UnaryOpType::logic_not) { - llvm_val[stmt] = builder->CreateSelect( - builder->CreateIsNull(input), - tlctx->get_constant(true), - tlctx->get_constant(false)); + llvm_val[stmt] = builder->CreateSelect(builder->CreateIsNull(input), + tlctx->get_constant(true), + tlctx->get_constant(false)); } else { TI_P(unary_op_type_name(op));