<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi,
<div><br>
</div>
<div>I've discovered a problem on Sparc processors (specifically, LEON, but I suspect but can't verify that it also happens on all Sparc processors).</div>
<div><br>
</div>
<div>The problem is, or appears to be with using double values in Sparc (32 bit).</div>
<div><br>
</div>
<div>Specifically, double values are not being loaded into registers correctly within a function using va_args. Only half the value is loaded (i.e. 32, rather than 64 bits of the value).</div>
<div><br>
</div>
<div>What I have also found is that the failure does not happen in all circumstances. The simplest situation I've been able to re-create that avoids the problem is to put a store and subsequent load instruction around the va_arg instruction that deals with
 the double value. e.g. (in an .ll file):</div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;">This code fragment does not work:</span></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div>
<div>  define void @foo(i32 %v, i8* %ap) local_unnamed_addr {</div>
<div>  entry:</div>
<div>    %ap.addr = alloca i8*, align 4</div>
<div>    store i8* %ap, i8** %ap.addr, align 4</div>
<div>    %0 = va_arg i8** %ap.addr, i64</div>
<div>    %conv = trunc i64 %0 to i32</div>
<div>    %1 = va_arg i8** %ap.addr, double</div>
</div>
<div>    ...</div>
<div><br>
</div>
<div>Whereas this nearly identical code fragment, wrapping the store and load around the "double" va_arg instruction does work:</div>
<div>
<div><br>
</div>
<div><span style="font-size: 10pt;">  define void @foo(i32 %v, i8* %ap) local_unnamed_addr {</span></div>
<div>    entry:</div>
<div>    %ap.addr = alloca i8*, align 4</div>
<div>    store i8* %ap, i8** %ap.addr, align 4</div>
<div>    %0 = va_arg i8** %ap.addr, i64</div>
<div>    %conv = trunc i64 %0 to i32</div>
<div>    store i32 %conv, i32* @foo_arg, align 4</div>
<div>    %1 = va_arg i8** %ap.addr, double</div>
<div>    %2 = load i32, i32* @foo_arg, align 4</div>
</div>
<div>    ...</div>
<div><br>
</div>
<div>I had been attempting to make various changes to SparcISelLowering.cpp to try to simulate something similar where the code is output, but I don't feel as though I'm heading in the right direction. I'm still not sure quite where the source of the problem
 lies.</div>
<div><br>
</div>
<div>I can provide more details on specifics, but rather than head off into excessive details immediately, I'd appreciate if anyone can help me identify what direction I really should be taking to fix this problem. I'm not convinced I've been going about it
 the right way so far.</div>
<div><br>
</div>
<div><span style="font-size: 10pt;">Chris Dewhurst, Lero, University of Limerick.</span></div>
</div>
</body>
</html>