From 52537ef22ff29c4e78afff41393376fe51bb5257 Mon Sep 17 00:00:00 2001 From: listerily Date: Mon, 15 May 2023 13:14:31 +0800 Subject: [PATCH] [llvm] Simplified and add support for type u1 in logical not operation ghstack-source-id: 95e72c89a07c15430ea7bf95a9741744d5e311fe Pull Request resolved: https://github.com/taichi-dev/taichi/pull/8004 --- 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 9d4f4ac10b39fa..5b2431ef54eb54 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 dd5b8216759085..b39586b3b446a5 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 30cd0f5aa382f2..81f43bd72b645e 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 460beb145e7e77..53547922a2e858 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)