Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2976,25 +2976,15 @@ } case Instruction::PtrToInt: { - const DataLayout &DL = getDataLayout(); - // 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: { 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: llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll =================================================================== --- llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll +++ /dev/null @@ -1,10 +0,0 @@ -; RUN: not --crash llc < %s -mtriple=i386-linux 2>&1 | FileCheck %s - -; ptrtoint expressions that cast to a wider integer type are not supported. -; A frontend can achieve a similar result by casting to the correct integer -; type and explicitly zeroing any additional bytes. -; { i32, i32 } { i32 ptrtoint (ptr @r to i32), i32 0 } - -; CHECK: LLVM ERROR: Unsupported expression in static initializer: ptrtoint (ptr @r to i64) - -@r = global i64 ptrtoint (ptr @r to i64) 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{{$}}