diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/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 diff --git a/llvm/test/CodeGen/X86/ptrtoint-narrow.ll b/llvm/test/CodeGen/X86/ptrtoint-narrow.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/ptrtoint-narrow.ll @@ -0,0 +1,6 @@ +; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s + +@ptr = external global i8, align 1 +@ref = constant i32 trunc (i64 ptrtoint (i8* @ptr to i64) to i32), align 4 + +; CHECK: .long ptr{{$}}