[PATCH] D61325: Treat a narrowing PtrToInt like Trunc when generating asm

Mat Hostetter via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 14:54:19 PDT 2019


mjhostet updated this revision to Diff 197451.
mjhostet added a comment.

Check .s output in test, rather than llc exit status creating .o.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61325/new/

https://reviews.llvm.org/D61325

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/X86/ptrtoint-narrow.ll


Index: llvm/test/CodeGen/X86/ptrtoint-narrow.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/ptrtoint-narrow.ll
@@ -0,0 +1,6 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+
+ at ptr = external global i8, align 1
+ at ref = constant i32 trunc (i64 ptrtoint (i8* @ptr to i64) to i32), align 4
+
+; CHECK: .long  ptr{{$}}
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2232,7 +2232,10 @@
 
     // We can emit the pointer value into this slot if the slot is an
     // integer slot equal to the size of the pointer.
-    if (DL.getTypeAllocSize(Ty) == DL.getTypeAllocSize(Op->getType()))
+    //
+    // If the pointer is larger than the resultant integer, then
+    // as with Trunc just depend on the assembler to truncate it.
+    if (DL.getTypeAllocSize(Ty) <= DL.getTypeAllocSize(Op->getType()))
       return OpExpr;
 
     // Otherwise the pointer is smaller than the resultant integer, mask off


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61325.197451.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190430/4dba538f/attachment.bin>


More information about the llvm-commits mailing list