[PATCH] D62775: [SelectionDAG] Skip addrspacecast expansion when casting undef values

Dylan McKay via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 1 06:49:32 PDT 2019


dylanmckay created this revision.
dylanmckay added reviewers: bogner, efriedma, kparzysz, TimNN, arsenm.
Herald added subscribers: atanasyan, JDevlieghere, arichardson, wdng, sdardis.
Herald added a project: LLVM.

This allows all targets to expand address space casts of undef values,
even if they do not explicitly have NOP addrspacecasts.

This bug was encountered whilst compiling the Rust libcore library for
AVR.

Prior to this, only targets that defined isNoopAddrSpaceCast() as true
could successfully lower an undef address space cast without custom
lowering logic.

The Mips and PowerPC backends, among others, could already handle these
addrspacecasts fine because SelectionDAG knew all addrspacecasts were NOPs.
Other backends including MSP430 and AVR would crash during ISel.
Now all backends will correctly lower this form of instruction without special
consideration from the backend authors.


Repository:
  rL LLVM

https://reviews.llvm.org/D62775

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  test/CodeGen/AVR/undef-addrspacecast.ll


Index: test/CodeGen/AVR/undef-addrspacecast.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AVR/undef-addrspacecast.ll
@@ -0,0 +1,10 @@
+; RUN: llc -mattr=avr6 < %s -march=avr | FileCheck %s
+
+; CHECK-LABEL: foo
+define void @foo() addrspace(1) {
+start:
+  %a = addrspacecast {} addrspace(1)* undef to {}*
+  store {}* %a, {}** undef, align 1
+  ret void
+}
+
Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3534,7 +3534,12 @@
   unsigned SrcAS = SV->getType()->getPointerAddressSpace();
   unsigned DestAS = I.getType()->getPointerAddressSpace();
 
-  if (!TLI.isNoopAddrSpaceCast(SrcAS, DestAS))
+  // Do not insert address space conversion code when the target doesn't
+  // require it. Also skip cast expansion when casting an undefined
+  // value, as a casted undefined value is still an undefined value.
+  // to make it point
+  if (!TLI.isNoopAddrSpaceCast(SrcAS, DestAS) &&
+      !isa<UndefValue>(SV))
     N = DAG.getAddrSpaceCast(getCurSDLoc(), DestVT, N, SrcAS, DestAS);
 
   setValue(&I, N);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62775.202547.patch
Type: text/x-patch
Size: 1249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190601/0b7469ac/attachment-0001.bin>


More information about the llvm-commits mailing list