store addrspace qualifier

How do I access the address qualifier from the store instruction.

Given the following code:

define void @test_unary_op_anegate(float %x, float addrspace(11)*
%result) nounwind {


        %neg = sub float -0.000000e+000, %x ; <float>

        store float %neg, float addrspace(11)* %result

        ret void


When I attempt to generate this code, I'm aborting on.

Cannot yet select: 017E8230: ch = store 017E7DF0, 017E8098, 017E8010,
017E81A8 <0035A078:0> alignment=4

So I am doing a custom Store function.

In my LowerStore function, I get an SDValue w/ opcode of 119(store) and
4 child Operands

Operand 0 is the entry token which I assume I can ignore

Operand 1 is the source data(%neg), which I finally can handle correctly
thanks to Eli

Operand 2 is the dst location with two children, an EntryToken and
Register(%result I'm guessing)

Operand 3 is undef

So, how do I find out the address space? The reason being different
address spaces are accessed with different registers.


Micah Villmow

Systems Engineer

Advanced Technology & Performance

Advanced Micro Devices Inc.

4555 Great America Pkwy,

Santa Clara, CA. 95054

P: 408-572-6219

F: 408-572-6596

The address qualifier is stored in the type of %result. From that operand, you can get the Value and then call getType. The type for result should be a PointerType which you cast to a PointerType and get the getAddressSpace e.g. cast(Ty)->getAddressSpace()

– Mon Ping

Mon Ping,

Thanks for the tip, but I can't for the life of me seem to get the
Value from a StoreSDNode. From looking at the SelectionDAGNodes header
file, the only class that has the getValue function call is
SrcValueSDNode that returns a Value type. The only class that has
getType is a ConstantPoolSDNode. I don't think that ConstantPoolSDNode
is what I want and when I try to cast the getBasePtr().Val of the
StoreSDNode to a SrcValueSDNode it asserts on:

Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible

This is what I'm attempting:

SDValue LangTargetLowering::LowerSTORE(SDValue Op, SelectionDAG& DAG){

    const StoreSDNode* storeOp = dyn_cast<StoreSDNode>(Op.Val);

    const SDValue& dstPtr = storeOp->getBasePtr();

    const SrcValueSDNode* svdstVal = cast<SrcValueSDNode>(dstPtr.Val);

    const Value* dstVal = svdstVal->getValue();

    int addressSpace = ADDRESS_NONE;

    const Type* dstType = dstVal->getType();

    if (isa<PointerType>(dstType)) {

        const PointerType* ptrType = cast<PointerType>(dstType);

        addressSpace = ptrType->getAddressSpace();


    printf("Addr: %d\n", addressSpace);

SDValue Res;


  return Res;


Any idea what I'm doing wrong or how I can get this to work correctly?




I'm working on more or less the same problem.

I'm exploring the following:

const Type* dstType = storeOp->getSrcValue()->getType();

New to this myself, but I think getSrcValue() (in MemSDNode, a base for StoreSDNode) returns a Value object which refers back to the original IR, where there's more detailed type info.

I see cases where the MemSDNode will get a NULL SrcValue (I see it in getStore/getLoad calls in LegalizeDAG.cpp), but these all seem to be referring to the stack.

So, I'm thinking:

const Value* v = storeOp->getSrcValue();
if( !v )
  addressSpace = stackAddressSpace;
  const Type* dstType = storeOp->getSrcValue()->getType();


Hi Micah,

I forgot that you are at a StoreSDNode. You can get the value directly from that node. Try something like

That should give you the type of the memory location.

– Mon Ping