<div dir="ltr">Ah! Okay, that makes sense except for one thing.<br><br>The getelementptr successfully dyn_cast<Constant>'ed. At first glance that figures since it is a constant expression. But from the inheritance diagram of Value, getelementptr is not a subclass of Constant but of Instruction; from that perspective I would expect that the fact that this particular one is a constant expression would be as far as the compiler is concerned just a dynamic fact based on the fact that its operands happen to be constants, so I wouldn't have expected the dynamic cast to succeed. What am I missing here? <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 8, 2015 at 10:10 AM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">----- Original Message -----<br>
> From: "Russell Wallace via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
> To: "llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
> Sent: Sunday, November 8, 2015 4:03:27 AM<br>
> Subject: [llvm-dev] Instruction not in sequence<br>
><br>
> This code:<br>
><br>
> int main(int argc, char **argv) {<br>
> puts("abc");<br>
> return 0;<br>
> }<br>
><br>
> compiles to this:<br>
><br>
> @"\01??_C@_03FIKCJHKP@abc?$AA@" = linkonce_odr unnamed_addr constant<br>
> [4 x i8] c"abc\00", comdat, align 1<br>
><br>
> ; Function Attrs: nounwind uwtable<br>
> define i32 @main(i32 %argc, i8** nocapture readnone %argv) #0 {<br>
> %1 = tail call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x<br>
> i8]* @"\01??_C@_03FIKCJHKP@abc?$AA@", i64 0, i64 0)) #2, !dbg !15<br>
> ret i32 0, !dbg !16<br>
> }<br>
><br>
> The part I don't understand is where the call instruction refers to<br>
> the result of getelementptr without the latter appearing in the<br>
> sequence of instructions. I thought all instructions appeared in<br>
> sequence in basic blocks, so I was expecting %1 = getelementptr ...,<br>
> %2 = call(%1 ...)<br>
><br>
> Is there something I'm missing about the rules for the intermediate<br>
> code representation?<br>
<br>
</div></div>The getelementptr here is not an instruction at all, but rather a constant expression. Constant expressions in LLVM can be complicated, and have expression nodes that mirror the usual IR instructions.<br>
<br>
A quick way to see this is to run your IR through llc -march=cpp.<br>
<br>
 -Hal<br>
<br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</font></span></blockquote></div><br></div>