[PATCH] D26923: [CodeGenPrepare] Don't sink non-cheap addrspacecasts.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 14:59:20 PST 2016


This revision was automatically updated to reflect the committed changes.
jlebar marked 2 inline comments as done.
Closed by commit rL287591: [CodeGenPrepare] Don't sink non-cheap addrspacecasts. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D26923?vs=78745&id=78790#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26923

Files:
  llvm/trunk/include/llvm/Target/TargetLowering.h
  llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
  llvm/trunk/test/Transforms/CodeGenPrepare/NVPTX/dont-sink-nop-addrspacecast.ll


Index: llvm/trunk/include/llvm/Target/TargetLowering.h
===================================================================
--- llvm/trunk/include/llvm/Target/TargetLowering.h
+++ llvm/trunk/include/llvm/Target/TargetLowering.h
@@ -1153,6 +1153,12 @@
     return false;
   }
 
+  /// Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g. we
+  /// are happy to sink it into basic blocks.
+  virtual bool isCheapAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const {
+    return isNoopAddrSpaceCast(SrcAS, DestAS);
+  }
+
   /// Return true if the pointer arguments to CI should be aligned by aligning
   /// the object whose address is being passed. If so then MinSize is set to the
   /// minimum size the object must be to be aligned and PrefAlign is set to the
Index: llvm/trunk/test/Transforms/CodeGenPrepare/NVPTX/dont-sink-nop-addrspacecast.ll
===================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/NVPTX/dont-sink-nop-addrspacecast.ll
+++ llvm/trunk/test/Transforms/CodeGenPrepare/NVPTX/dont-sink-nop-addrspacecast.ll
@@ -0,0 +1,21 @@
+; RUN: opt -S -codegenprepare < %s | FileCheck %s
+
+target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
+target triple = "nvptx64-nvidia-cuda"
+
+; CHECK-LABEL: @test
+define i64 @test(i1 %pred, i64* %ptr) {
+; CHECK: addrspacecast
+  %ptr_as1 = addrspacecast i64* %ptr to i64 addrspace(1)*
+  br i1 %pred, label %l1, label %l2
+l1:
+; CHECK-LABEL: l1:
+; CHECK-NOT: addrspacecast
+  %v1 = load i64, i64* %ptr
+  ret i64 %v1
+l2:
+  ; CHECK-LABEL: l2:
+  ; CHECK-NOT: addrspacecast
+  %v2 = load i64, i64 addrspace(1)* %ptr_as1
+  ret i64 %v2
+}
Index: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
@@ -927,6 +927,14 @@
 ///
 static bool OptimizeNoopCopyExpression(CastInst *CI, const TargetLowering &TLI,
                                        const DataLayout &DL) {
+  // Sink only "cheap" (or nop) address-space casts.  This is a weaker condition
+  // than sinking only nop casts, but is helpful on some platforms.
+  if (auto *ASC = dyn_cast<AddrSpaceCastInst>(CI)) {
+    if (!TLI.isCheapAddrSpaceCast(ASC->getSrcAddressSpace(),
+                                  ASC->getDestAddressSpace()))
+      return false;
+  }
+
   // If this is a noop copy,
   EVT SrcVT = TLI.getValueType(DL, CI->getOperand(0)->getType());
   EVT DstVT = TLI.getValueType(DL, CI->getType());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26923.78790.patch
Type: text/x-patch
Size: 2556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161121/d61e00fa/attachment.bin>


More information about the llvm-commits mailing list