Xiaolong Tang
2010-Jun-18 11:54 UTC
[LLVMdev] Question on Load and GetElementPtr instructions
Hey, Considering the following instruction: %20 = load %struct.Node** getelementptr inbounds (%struct.Node* @head, i32 0, i32 0), align 16 ; <%struct.Node*> [#uses=1] What is the type of the first operand of the instruction (i.e., getOperand(0))? I thought the operand is a "GetElementPtr" instruction, however, the predicate "isa<Instruction>()" over the operand returns false. So, I am confused. Can someone clarify the above instruction for me? By the way, why does not LLVM factor out the operand and instead generate such two instructions: %19 = getelementptr inbounds (%struct.Node* @head, i32 0, i32 0) %20 = load %struct.Node** %19, align 16 ; <%struct.Node*> [#uses=1] What it the cause? What are the differences between the "GetElementPtr inbounds" instruction and just the "GetElementPtr" instruction? Thanks, Xiaolong
NAKAMURA Takumi
2010-Jun-18 12:16 UTC
[LLVMdev] Question on Load and GetElementPtr instructions
Good evening, Tang.> What is the type of the first operand of the instruction (i.e., > getOperand(0))?It might be ConstantExpr. You may use dyn_cast<GEPOperator>(getPointerOperand()). Also GetElementPtrInst* can be casted to GEPOperator. ...Takumi 2010/6/18 Xiaolong Tang <xiaolong.snake at gmail.com>:> > Hey, > > Considering the following instruction: > > %20 = load %struct.Node** getelementptr inbounds (%struct.Node* > @head, i32 0, i32 0), align 16 ; <%struct.Node*> [#uses=1] > > What is the type of the first operand of the instruction (i.e., > getOperand(0))? > > I thought the operand is a "GetElementPtr" instruction, however, the > predicate "isa<Instruction>()" over the operand returns false. > So, I am confused. Can someone clarify the above instruction for me? > > By the way, why does not LLVM factor out the operand and instead > generate such two instructions: > > %19 = getelementptr inbounds (%struct.Node* @head, i32 0, i32 0) > %20 = load %struct.Node** %19, align 16 ; <%struct.Node*> [#uses=1] > > What it the cause? What are the differences between the > "GetElementPtr inbounds" instruction and just the "GetElementPtr" > instruction? > > > Thanks, > Xiaolong
Xiaolong Tang
2010-Jun-18 12:40 UTC
[LLVMdev] Question on Load and GetElementPtr instructions
Hello Nakamura,> > What is the type of the first operand of the instruction (i.e., > > getOperand(0))? > > It might be ConstantExpr. > You may use dyn_cast<GEPOperator>(getPointerOperand()). > Also GetElementPtrInst* can be casted to GEPOperator.You are right. Now I use isa<GEPOperator> as the guard. Thanks. Best, Xiaolong> > > 2010/6/18 Xiaolong Tang <xiaolong.snake at gmail.com>: > > > > Hey, > > > > Considering the following instruction: > > > > %20 = load %struct.Node** getelementptr inbounds (%struct.Node* > > @head, i32 0, i32 0), align 16 ; <%struct.Node*> [#uses=1] > > > > What is the type of the first operand of the instruction (i.e., > > getOperand(0))? > > > > I thought the operand is a "GetElementPtr" instruction, however, the > > predicate "isa<Instruction>()" over the operand returns false. > > So, I am confused. Can someone clarify the above instruction for me? > > > > By the way, why does not LLVM factor out the operand and instead > > generate such two instructions: > > > > %19 = getelementptr inbounds (%struct.Node* @head, i32 0, i32 0) > > %20 = load %struct.Node** %19, align 16 ; <%struct.Node*> [#uses=1] > > > > What it the cause? What are the differences between the > > "GetElementPtr inbounds" instruction and just the "GetElementPtr" > > instruction?
Duncan Sands
2010-Jun-18 12:42 UTC
[LLVMdev] Question on Load and GetElementPtr instructions
Hi Xiaolong,> Considering the following instruction: > > %20 = load %struct.Node** getelementptr inbounds (%struct.Node* > @head, i32 0, i32 0), align 16 ;<%struct.Node*> [#uses=1] > > What is the type of the first operand of the instruction (i.e., > getOperand(0))? > > I thought the operand is a "GetElementPtr" instruction, however, the > predicate "isa<Instruction>()" over the operand returns false. > So, I am confused. Can someone clarify the above instruction for me?it is not an Instruction, it is a ConstantExpr. Several expressions like GEP exist both as instructions and as constants, see the ConstantExpr class. Ciao, Duncan.
Apparently Analagous Threads
- [LLVMdev] Question on Load and GetElementPtr instructions
- [LLVMdev] How to get the indices in an getelementptr Value?
- Cast a function parameter to GEP
- [LLVMdev] How to get the indices in an getelementptr Value?
- [LLVMdev] How to get more details from storeInst ?