This is an automated email from the ASF dual-hosted git repository.

kparzysz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 1c5442d2e9 [Codegen][LLVM] Remove cast to i8* in builtin::address_of 
(#14563)
1c5442d2e9 is described below

commit 1c5442d2e958e8b698a550e35a74684b38398b54
Author: Eric Lunderberg <lunderb...@users.noreply.github.com>
AuthorDate: Tue Apr 11 14:06:15 2023 -0500

    [Codegen][LLVM] Remove cast to i8* in builtin::address_of (#14563)
    
    * [Codegen][LLVM] Remove cast to i8* in builtin::address_of
    
    This cast was initially added when `CreateBufferPtr` did not include
    the cast to the appropriate address space, and is no longer
    necessary.  Removing the cast will not harm LLVM configurations with
    opaque pointers ([default in LLVM
    
15+](https://github.com/llvm/llvm-project/blob/main/llvm/docs/OpaquePointers.rst)),
    and avoids type mismatches when using LLVM configurations that use
    typed pointers.
    
    * Added handling of i8* argument to non-overloaded prefetch
    
    For compatibility with earlier versions of LLVM.  Newer versions have
    an overloaded prefetch intrinsic, and the pointer cast is unnecessary.
---
 src/target/llvm/codegen_llvm.cc | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/target/llvm/codegen_llvm.cc b/src/target/llvm/codegen_llvm.cc
index 7c32f3cfa1..69fe8aa2b7 100644
--- a/src/target/llvm/codegen_llvm.cc
+++ b/src/target/llvm/codegen_llvm.cc
@@ -1279,6 +1279,19 @@ llvm::Value* CodeGenLLVM::CreateIntrinsic(const 
CallNode* op) {
 #else
               << llvm::Intrinsic::getName(id, {});
 #endif
+
+    // In earlier versions of LLVM's, the prefetch intrinsic is not
+    // overloaded, and always takes the first argument as i8*.  If
+    // this is the case, this argument should insert a cast to i8*.
+    if (id == llvm::Intrinsic::prefetch) {
+      llvm::Type* param_type = f->arg_begin()->getType();
+      if (param_type != arg_value[0]->getType()) {
+        unsigned addrspace =
+            
llvm::dyn_cast<llvm::PointerType>(arg_value[0]->getType())->getAddressSpace();
+        arg_value[0] = builder_->CreatePointerCast(arg_value[0], 
t_char_->getPointerTo(addrspace));
+      }
+    }
+
     return builder_->CreateCall(f, arg_value);
   } else if (op->op.same_as(builtin::bitwise_and())) {
     return builder_->CreateAnd(MakeValue(op->args[0]), MakeValue(op->args[1]));
@@ -1314,9 +1327,7 @@ llvm::Value* CodeGenLLVM::CreateIntrinsic(const CallNode* 
op) {
 
     TypedPointer buffer_ptr = CreateBufferPtr(MakeValue(load->buffer->data), 
load->buffer->dtype,
                                               indices_val, load->dtype);
-    unsigned addrspace =
-        
llvm::dyn_cast<llvm::PointerType>(buffer_ptr.addr->getType())->getAddressSpace();
-    return builder_->CreatePointerCast(buffer_ptr.addr, 
t_char_->getPointerTo(addrspace));
+    return buffer_ptr.addr;
   } else if (op->op.same_as(builtin::reinterpret()) && is_zero(op->args[0])) {
     return llvm::Constant::getNullValue(t_void_p_);
   } else if (op->op.same_as(builtin::isnullptr())) {

Reply via email to