[PATCH] D143602: Allow 32-bit pointers to be written in 64-bit slots
David M. Lloyd via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 9 07:27:57 PST 2023
dmlloyd updated this revision to Diff 496123.
dmlloyd added a comment.
Another attempt to quell the build failures that I cannot reproduce locally.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143602/new/
https://reviews.llvm.org/D143602
Files:
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
test/CodeGen/WebAssembly/ptrtoint-widen.ll
test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
test/CodeGen/X86/ptrtoint-widen.ll
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
+
+ at ptr = external global i8, align 1
+ at ref = constant i64 ptrtoint (ptr @ptr to i64), align 8
+
+; CHECK: .quad 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)
-
- at r = global i64 ptrtoint (ptr @r to i64)
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
+
+ at ptr = external global i8, align 1
+ at ref = constant i64 ptrtoint (ptr @ptr to i64), align 8
+
+; CHECK: .int64 ptr{{$}}
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: {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143602.496123.patch
Type: text/x-patch
Size: 2690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230209/bb93b0b4/attachment.bin>
More information about the llvm-commits
mailing list