Skip to content
Prev Previous commit
Next Next commit
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.6-beta.1 [skip ci]
  • Loading branch information
arichardson committed Jun 11, 2025
commit 1edb3b45a26ec1b60ccf08259f9aede5d5e5ebc9
3 changes: 1 addition & 2 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ class TargetTransformInfoImplBase {
}
case Instruction::PtrToAddr: {
unsigned DstSize = Dst->getScalarSizeInBits();
if (DL.isLegalInteger(DstSize) &&
DstSize >= DL.getPointerAddressSizeInBits(Src))
if (DL.isLegalInteger(DstSize) && DstSize >= DL.getAddressSizeInBits(Src))
return 0;
break;
}
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ class IRTranslator : public MachineFunctionPass {
return translateCast(TargetOpcode::G_PTRTOINT, U, MIRBuilder);
}
bool translatePtrToAddr(const User &U, MachineIRBuilder &MIRBuilder) {
// FIXME: this is not correct for pointers with addr width != pointer width
return translatePtrToInt(U, MIRBuilder);
}
bool translateTrunc(const User &U, MachineIRBuilder &MIRBuilder) {
Expand Down
28 changes: 14 additions & 14 deletions llvm/include/llvm/IR/DataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ class DataLayout {
LLVM_ABI Align getPointerPrefAlignment(unsigned AS = 0) const;

/// The pointer representation size in bytes, rounded up to a whole number of
/// bytes. The difference between this function and getPointerAddressSize() is
/// this one returns the size of the entire pointer type (this includes
/// bytes. The difference between this function and getAddressSize() is that
/// this one returns the size of the entire pointer representation (including
/// metadata bits for fat pointers) and the latter only returns the number of
/// address bits.
/// \sa DataLayout::getPointerAddressSizeInBits
/// \sa DataLayout::getAddressSizeInBits
/// FIXME: The defaults need to be removed once all of
/// the backends/clients are updated.
LLVM_ABI unsigned getPointerSize(unsigned AS = 0) const;
Expand All @@ -342,9 +342,9 @@ class DataLayout {
/// only 64 are used to represent the address and the remaining ones are used
/// for metadata such as bounds and access permissions. In this case
/// getPointerSize() returns 16, but getIndexSize() returns 8.
/// To help with code understanding, the alias getPointerAddressSize() can be
/// used instead of getIndexSize() to clarify that an address width is needed.
unsigned getIndexSize(unsigned AS) const;
/// To help with code understanding, the alias getAddressSize() can be used
/// instead of getIndexSize() to clarify that an address width is needed.
LLVM_ABI unsigned getIndexSize(unsigned AS) const;

/// The integral size of a pointer in a given address space in bytes, which
/// is defined to be the same as getIndexSize(). This exists as a separate
Expand All @@ -354,8 +354,8 @@ class DataLayout {
/// 48-bit addresses and 32-bit offsets indexing), there is currently no need
/// to differentiate these properties in LLVM.
/// \sa DataLayout::getIndexSize
/// \sa DataLayout::getPointerAddressSizeInBits
unsigned getPointerAddressSize(unsigned AS) const { return getIndexSize(AS); }
/// \sa DataLayout::getAddressSizeInBits
unsigned getAddressSize(unsigned AS) const { return getIndexSize(AS); }

/// Return the address spaces containing non-integral pointers. Pointers in
/// this address space don't have a well-defined bitwise representation.
Expand Down Expand Up @@ -384,7 +384,7 @@ class DataLayout {
/// The size in bits of the pointer representation in a given address space.
/// This is not necessarily the same as the integer address of a pointer (e.g.
/// for fat pointers).
/// \sa DataLayout::getPointerAddressSizeInBits()
/// \sa DataLayout::getAddressSizeInBits()
/// FIXME: The defaults need to be removed once all of
/// the backends/clients are updated.
unsigned getPointerSizeInBits(unsigned AS = 0) const {
Expand All @@ -394,7 +394,7 @@ class DataLayout {
/// The size in bits of indices used for address calculation in getelementptr
/// and for addresses in the given AS. See getIndexSize() for more
/// information.
/// \sa DataLayout::getPointerAddressSizeInBits()
/// \sa DataLayout::getAddressSizeInBits()
unsigned getIndexSizeInBits(unsigned AS) const {
return getPointerSpec(AS).IndexBitWidth;
}
Expand All @@ -404,7 +404,7 @@ class DataLayout {
/// target that requires these two properties to have different values. See
/// getIndexSize() for more information.
/// \sa DataLayout::getIndexSizeInBits()
unsigned getPointerAddressSizeInBits(unsigned AS) const {
unsigned getAddressSizeInBits(unsigned AS) const {
return getIndexSizeInBits(AS);
}

Expand All @@ -417,14 +417,14 @@ class DataLayout {

/// The size in bits of the index used in GEP calculation for this type.
/// The function should be called with pointer or vector of pointers type.
/// This is defined to return the same value as getPointerAddressSizeInBits(),
/// This is defined to return the same value as getAddressSizeInBits(),
/// but separate functions exist for code clarity.
unsigned getIndexTypeSizeInBits(Type *Ty) const;
LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const;

/// The size in bits of an address for this type.
/// This is defined to return the same value as getIndexTypeSizeInBits(),
/// but separate functions exist for code clarity.
unsigned getPointerAddressSizeInBits(Type *Ty) const {
unsigned getAddressSizeInBits(Type *Ty) const {
return getIndexTypeSizeInBits(Ty);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/InstVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class InstVisitor {
RetTy visitUIToFPInst(UIToFPInst &I) { DELEGATE(CastInst);}
RetTy visitSIToFPInst(SIToFPInst &I) { DELEGATE(CastInst);}
RetTy visitPtrToIntInst(PtrToIntInst &I) { DELEGATE(CastInst);}
RetTy visitPtrToAddrInst(PtrToAddrInst &I) { DELEGATE(PtrToIntInst);}
RetTy visitPtrToAddrInst(PtrToAddrInst &I) { DELEGATE(CastInst);}
RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
RetTy visitAddrSpaceCastInst(AddrSpaceCastInst &I) { DELEGATE(CastInst);}
Expand Down
23 changes: 15 additions & 8 deletions llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4918,9 +4918,6 @@ class PtrToIntInst : public CastInst {
/// Clone an identical PtrToIntInst.
LLVM_ABI PtrToIntInst *cloneImpl() const;

PtrToIntInst(unsigned Op, Value *S, Type *Ty, const Twine &NameStr,
InsertPosition InsertBefore);

public:
/// Constructor with insert-before-instruction semantics
LLVM_ABI
Expand All @@ -4945,17 +4942,16 @@ class PtrToIntInst : public CastInst {

// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Instruction *I) {
return I->getOpcode() == PtrToInt || I->getOpcode() == PtrToAddr;
return I->getOpcode() == PtrToInt;
}
static bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
};

/// This class represents a cast from a pointer to an address (non-capturing
/// ptrtoint). Inherits from PtrToIntInst since it is a less restrictive version
/// of ptrtoint, so treating it as ptrtoint is conservatively correct.
class PtrToAddrInst : public PtrToIntInst {
/// ptrtoint).
class PtrToAddrInst : public CastInst {
protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
Expand All @@ -4972,6 +4968,18 @@ class PtrToAddrInst : public PtrToIntInst {
nullptr ///< Where to insert the new instruction
);

/// Gets the pointer operand.
Value *getPointerOperand() { return getOperand(0); }
/// Gets the pointer operand.
const Value *getPointerOperand() const { return getOperand(0); }
/// Gets the operand index of the pointer operand.
static unsigned getPointerOperandIndex() { return 0U; }

/// Returns the address space of the pointer operand.
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}

// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Instruction *I) {
return I->getOpcode() == PtrToAddr;
Expand All @@ -4981,7 +4989,6 @@ class PtrToAddrInst : public PtrToIntInst {
}
};


//===----------------------------------------------------------------------===//
// BitCastInst Class
//===----------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3884,6 +3884,7 @@ void SelectionDAGBuilder::visitSIToFP(const User &I) {
}

void SelectionDAGBuilder::visitPtrToAddr(const User &I) {
// FIXME: this is not correct for pointers with addr width != pointer width
visitPtrToInt(I);
}

Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/IR/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,7 @@ unsigned CastInst::isEliminableCastPair(
// same reason.
const unsigned numCastOps =
Instruction::CastOpsEnd - Instruction::CastOpsBegin;
// clang-format off
static const uint8_t CastResults[numCastOps][numCastOps] = {
// T F F U S F F P P I B A -+
// R Z S P P I I T P 2 2 N T S |
Expand All @@ -2872,6 +2873,7 @@ unsigned CastInst::isEliminableCastPair(
{ 5, 5, 5, 0, 0, 5, 5, 0, 0,16,16, 5, 1,14}, // BitCast |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12}, // AddrSpaceCast -+
};
// clang-format on

// TODO: This logic could be encoded into the table above and handled in the
// switch below.
Expand Down Expand Up @@ -3453,19 +3455,17 @@ FPToSIInst::FPToSIInst(Value *S, Type *Ty, const Twine &Name,
assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
}

PtrToIntInst::PtrToIntInst(unsigned Op, Value *S, Type *Ty, const Twine &Name,
PtrToIntInst::PtrToIntInst(Value *S, Type *Ty, const Twine &Name,
InsertPosition InsertBefore)
: CastInst(Ty, Op, S, Name, InsertBefore) {
: CastInst(Ty, PtrToInt, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
}

PtrToIntInst::PtrToIntInst(Value *S, Type *Ty, const Twine &Name,
InsertPosition InsertBefore)
: PtrToIntInst(PtrToInt, S, Ty, Name, InsertBefore) {}

PtrToAddrInst::PtrToAddrInst(Value *S, Type *Ty, const Twine &Name,
InsertPosition InsertBefore)
: PtrToIntInst(PtrToAddr, S, Ty, Name, InsertBefore) {}
: CastInst(Ty, PtrToAddr, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToAddr");
}

IntToPtrInst::IntToPtrInst(Value *S, Type *Ty, const Twine &Name,
InsertPosition InsertBefore)
Expand Down
19 changes: 5 additions & 14 deletions llvm/test/Assembler/ptrtoaddr-const.ll
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
; RUN: not llvm-as --disable-output < %s 2>&1 | FileCheck %s
; ptrtoaddr is not currently support in constant expressions

target datalayout = "p1:64:64:64:32"

define i32 @test_as0(ptr %p) {
%addr = ptrtoaddr ptr %p to i32
; CHECK: %addr = ptrtoaddr ptr %p to i32
ret i32 %addr
}

define i16 @test_as1(ptr addrspace(1) %p) {
%addr = ptrtoaddr ptr addrspace(1) %p to i16
; CHECK: %addr = ptrtoaddr ptr addrspace(1) %p to i16
ret i16 %addr
}
@i = global i32 0
@global_cast = global i32 ptrtoaddr (ptr @i0 to i32)
; CHECK: [[#@LINE-1]]:27: error: expected value token
18 changes: 13 additions & 5 deletions llvm/test/Assembler/ptrtoaddr.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
; ptrtoaddr is not currently support in constant expressions
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
target datalayout = "p1:64:64:64:32"

@i = global i32 0
@global_cast = global i32 ptrtoaddr (ptr @i0 to i32)
; CHECK: [[#@LINE-1]]:27: error: expected value token
define i32 @test_as0(ptr %p) {
%addr = ptrtoaddr ptr %p to i32
; CHECK: %addr = ptrtoaddr ptr %p to i32
ret i32 %addr
}

define i16 @test_as1(ptr addrspace(1) %p) {
%addr = ptrtoaddr ptr addrspace(1) %p to i16
; CHECK: %addr = ptrtoaddr ptr addrspace(1) %p to i16
ret i16 %addr
}
14 changes: 14 additions & 0 deletions llvm/test/Bitcode/ptrtoaddr.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
target datalayout = "p1:64:64:64:32"

define i32 @test_as0(ptr %p) {
%addr = ptrtoaddr ptr %p to i32
; CHECK: %addr = ptrtoaddr ptr %p to i32
ret i32 %addr
}

define i16 @test_as1(ptr addrspace(1) %p) {
%addr = ptrtoaddr ptr addrspace(1) %p to i16
; CHECK: %addr = ptrtoaddr ptr addrspace(1) %p to i16
ret i16 %addr
}
17 changes: 4 additions & 13 deletions llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ define i32 @ptrtoint_offset(ptr addrspace(7) %ptr) {
define i32 @ptrtoaddr(ptr addrspace(7) %ptr) {
; CHECK-LABEL: define i32 @ptrtoaddr
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[PTR:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[PTR_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 0
; CHECK-NEXT: [[RET:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 1
; CHECK-NEXT: [[RET:%.*]] = ptrtoaddr { ptr addrspace(8), i32 } [[PTR]] to i32
; CHECK-NEXT: ret i32 [[RET]]
;
%ret = ptrtoaddr ptr addrspace(7) %ptr to i32
Expand All @@ -269,8 +268,7 @@ define i32 @ptrtoaddr(ptr addrspace(7) %ptr) {
define <2 x i32> @ptrtoaddr_vec(<2 x ptr addrspace(7)> %ptr) {
; CHECK-LABEL: define <2 x i32> @ptrtoaddr_vec
; CHECK-SAME: ({ <2 x ptr addrspace(8)>, <2 x i32> } [[PTR:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[PTR_RSRC:%.*]] = extractvalue { <2 x ptr addrspace(8)>, <2 x i32> } [[PTR]], 0
; CHECK-NEXT: [[RET:%.*]] = extractvalue { <2 x ptr addrspace(8)>, <2 x i32> } [[PTR]], 1
; CHECK-NEXT: [[RET:%.*]] = ptrtoaddr { <2 x ptr addrspace(8)>, <2 x i32> } [[PTR]] to <2 x i32>
; CHECK-NEXT: ret <2 x i32> [[RET]]
;
%ret = ptrtoaddr <2 x ptr addrspace(7)> %ptr to <2 x i32>
Expand All @@ -282,12 +280,7 @@ define <2 x i32> @ptrtoaddr_vec(<2 x ptr addrspace(7)> %ptr) {
define i160 @ptrtoaddr_ext(ptr addrspace(7) %ptr) {
; CHECK-LABEL: define i160 @ptrtoaddr_ext
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[PTR:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[PTR_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 0
; CHECK-NEXT: [[PTR_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 1
; CHECK-NEXT: [[RET_RSRC:%.*]] = ptrtoint ptr addrspace(8) [[PTR_RSRC]] to i160
; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i160 [[RET_RSRC]], 32
; CHECK-NEXT: [[RET_OFF:%.*]] = zext i32 [[PTR_OFF]] to i160
; CHECK-NEXT: [[RET:%.*]] = or i160 [[TMP1]], [[RET_OFF]]
; CHECK-NEXT: [[RET:%.*]] = ptrtoaddr { ptr addrspace(8), i32 } [[PTR]] to i160
; CHECK-NEXT: ret i160 [[RET]]
;
%ret = ptrtoaddr ptr addrspace(7) %ptr to i160
Expand All @@ -297,9 +290,7 @@ define i160 @ptrtoaddr_ext(ptr addrspace(7) %ptr) {
define i16 @ptrtoaddr_trunc(ptr addrspace(7) %ptr) {
; CHECK-LABEL: define i16 @ptrtoaddr_trunc
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[PTR:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[PTR_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 0
; CHECK-NEXT: [[PTR_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 1
; CHECK-NEXT: [[RET:%.*]] = trunc i32 [[PTR_OFF]] to i16
; CHECK-NEXT: [[RET:%.*]] = ptrtoaddr { ptr addrspace(8), i32 } [[PTR]] to i16
; CHECK-NEXT: ret i16 [[RET]]
;
%ret = ptrtoaddr ptr addrspace(7) %ptr to i16
Expand Down
24 changes: 19 additions & 5 deletions llvm/test/CodeGen/X86/GlobalISel/ptrtoaddr.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=CHECK
; RUN: llc -mtriple=x86_64-linux-gnu -global-isel < %s -o - | FileCheck %s --check-prefix=CHECK

define i1 @ptrtoaddr_1(ptr %p) {
; CHECK-LABEL: ptrtoaddr_1:
Expand Down Expand Up @@ -40,8 +40,8 @@ entry:
ret i16 %ret
}

define i32 @ptrtoaddr_s32_p0(ptr %p) {
; CHECK-LABEL: ptrtoaddr_s32_p0:
define i32 @ptrtoaddr_32(ptr %p) {
; CHECK-LABEL: ptrtoaddr_32:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: notl %eax
Expand All @@ -53,8 +53,8 @@ entry:
ret i32 %ret
}

define i64 @ptrtoaddr_s64_p0(ptr %p) {
; CHECK-LABEL: ptrtoaddr_s64_p0:
define i64 @ptrtoaddr_64(ptr %p) {
; CHECK-LABEL: ptrtoaddr_64:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: notq %rax
Expand All @@ -64,3 +64,17 @@ entry:
%ret = xor i64 %addr, -1
ret i64 %ret
}

define i128 @ptrtoaddr_128(ptr %p) {
; CHECK-LABEL: ptrtoaddr_128:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: xorl %edx, %edx
; CHECK-NEXT: notq %rax
; CHECK-NEXT: notq %rdx
; CHECK-NEXT: retq
entry:
%addr = ptrtoaddr ptr %p to i128
%ret = xor i128 %addr, -1
ret i128 %ret
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.