Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2975,27 +2975,16 @@ return lowerConstant(Op); } - case Instruction::PtrToInt: { - const DataLayout &DL = getDataLayout(); - + case Instruction::PtrToInt: // Support only foldable casts to/from pointers that can be eliminated by // changing the pointer to the appropriately sized integer type. - Constant *Op = CE->getOperand(0); - Type *Ty = CE->getType(); - - const MCExpr *OpExpr = lowerConstant(Op); - + // // We can emit the pointer value into this slot if the slot is an - // integer slot equal to the size of the pointer. + // integer slot. // - // 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).getFixedValue() <= - DL.getTypeAllocSize(Op->getType()).getFixedValue()) - return OpExpr; - - break; // Error - } + // If the pointer is larger or smaller than the resultant integer, then + // just depend on the assembler to truncate or extend it. + return lowerConstant(CE->getOperand(0)); case Instruction::Sub: { GlobalValue *LHSGV; Index: test/CodeGen/WebAssembly/ptrtoint-widen.ll =================================================================== --- /dev/null +++ test/CodeGen/WebAssembly/ptrtoint-widen.ll @@ -0,0 +1,6 @@ +; RUN: llc < %s -mtriple=wasm32-unknown-unknown | FileCheck %s + +@ptr = external global i8, align 1 +@ref = constant i64 ptrtoint (ptr @ptr to i64), align 8 + +; CHECK: .int64 ptr{{$}} Index: test/CodeGen/X86/ptrtoint-widen.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/ptrtoint-widen.ll @@ -0,0 +1,6 @@ +; RUN: llc < %s -mtriple=i686-unknown-linux-gnu | FileCheck %s + +@ptr = external global i8, align 1 +@ref = constant i64 ptrtoint (ptr @ptr to i64), align 8 + +; CHECK: .quad ptr{{$}}