<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.32.2">
</HEAD>
<BODY>
I'm having some trouble trying to workout how to form functions from the c interface<BR>
I thought I had it sorted but I guess I'm missing something or haven't understood <BR>
the requirements, a case of trial and error and not really having a clue to start with! <BR>
<BR>
I've got binary ops, cmps, for loops, while loops working but then it hit the <BR>
wall with a tail cmp loop. <BR>
<BR>
looking at the output from the c interface it looks ok to me <BR>
but the optimizer is returning the wrong variable<BR>
I don't know what to do to avoid it?<BR>
<BR>
source language input <BR>
<BR>
Procedure TRU(a,b) <BR>
Protected x,y,c <BR>
Repeat <BR>
y=0<BR>
Repeat <BR>
c+x+y<BR>
y+1 <BR>
Until y >= b <BR>
x+1 <BR>
Until x >= a <BR>
ProcedureReturn c<BR>
EndProcedure <BR>
<BR>
output generated via the c Interface <BR>
<BR>
define i32 @TRU(i32 %a, i32 %b) {<BR>
Entry:<BR>
%a1 = alloca i32<BR>
store i32 %a, i32* %a1<BR>
%b2 = alloca i32<BR>
store i32 %b, i32* %b2<BR>
%c = alloca i32<BR>
store i32 0, i32* %c<BR>
%x = alloca i32<BR>
store i32 0, i32* %x<BR>
%y = alloca i32<BR>
store i32 0, i32* %y<BR>
br label %Repeat1<BR>
<BR>
Repeat1: ; preds = %Until1, %Entry<BR>
store i32 0, i32* %y<BR>
br label %Repeat2<BR>
<BR>
Repeat2: ; preds = %Until2, %Repeat1<BR>
%x3 = load i32* %x<BR>
%y4 = load i32* %y<BR>
%add = add i32 %x3, %y4<BR>
%c5 = load i32* %c<BR>
%add6 = add i32 %c5, %add<BR>
store i32 %add6, i32* %c<BR>
%y7 = load i32* %y<BR>
%add8 = add i32 %y7, 1<BR>
store i32 %add8, i32* %y<BR>
br label %Until2<BR>
<BR>
Until2: ; preds = %Repeat2<BR>
%y9 = load i32* %y<BR>
%b10 = load i32* %b2<BR>
%cond = icmp sge i32 %y9, %b10<BR>
br i1 %cond, label %Repeat2, label %Untilcmp2<BR>
<BR>
Untilcmp2: ; preds = %Until2<BR>
%x11 = load i32* %x<BR>
%add12 = add i32 %x11, 1<BR>
store i32 %add12, i32* %x<BR>
br label %Until1<BR>
<BR>
Until1: ; preds = %Untilcmp2<BR>
%x13 = load i32* %x<BR>
%a14 = load i32* %a1<BR>
%cond15 = icmp sge i32 %x13, %a14<BR>
br i1 %cond15, label %Repeat1, label %Untilcmp1<BR>
<BR>
Untilcmp1: ; preds = %Until1<BR>
%c16 = load i32* %c<BR>
ret i32 %c16<BR>
}<BR>
<BR>
verifying module<BR>
Optimize Function<BR>
Run in JIT<BR>
Jit Result: = 0 <BR>
should = 325<BR>
<BR>
dump the optimized module <BR>
<BR>
define i32 @TRU(i32 %a, i32 %b) {<BR>
Entry:<BR>
br label %Repeat1<BR>
<BR>
Repeat1: ; preds = %Untilcmp2, %Entry<BR>
%c.0 = phi i32 [ 0, %Entry ], [ %add6, %Untilcmp2 ]<BR>
%x.0 = phi i32 [ 0, %Entry ], [ %add12, %Untilcmp2 ]<BR>
br label %Repeat2<BR>
<BR>
Repeat2: ; preds = %Repeat2, %Repeat1<BR>
%c.1 = phi i32 [ %c.0, %Repeat1 ], [ %add6, %Repeat2 ]<BR>
%y.0 = phi i32 [ 0, %Repeat1 ], [ %add8, %Repeat2 ]<BR>
%add = add i32 %c.1, %x.0<BR>
%add6 = add i32 %add, %y.0<BR>
%add8 = add i32 %y.0, 1<BR>
%cond = icmp slt i32 %add8, %b<BR>
br i1 %cond, label %Untilcmp2, label %Repeat2<BR>
<BR>
Untilcmp2: ; preds = %Repeat2<BR>
%add12 = add i32 %x.0, 1<BR>
%cond15 = icmp slt i32 %add12, %a<BR>
br i1 %cond15, label %Untilcmp1, label %Repeat1<BR>
<BR>
Untilcmp1: ; preds = %Untilcmp2<BR>
ret i32 %add6<BR>
}<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>
--
Andrew Ferguson
</PRE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>