<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 9pt;
font-family:新細明體
}
</style>
</head>
<body class='hmmessage'>
I have been doing some playing with the patterns that define complex<BR>instructions, and I saw a behavior that doesn't look right.<BR>I think its a bug in the PPC backend.<BR>
<BR>
The 32-bit PPC .td file defines a pattern for the fnmsubs instruction like this:<BR>
<BR>
def : Pat<(fsub F4RC:$B, (fmul F4RC:$A, F4RC:$C)),<BR> (FNMSUBS F4RC:$A, F4RC:$C, F4RC:$B)>,<BR> Requires<[FPContractions]>;<BR>
<BR>
The unique feature of this parttern is that it maps a pair of<BR>LLVM IR instructions into a single PPC instruction.<BR>
<BR>
def FNMSUBS : AForm_1<59, 30,(outs F4RC:$FRT), (ins F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),<BR> "fnmsubs $FRT, $FRA, $FRC, $FRB", FPGeneral,<BR> [(set F4RC:$FRT, (fneg (fsub (fmul F4RC:$FRA, F4RC:$FRC),F4RC:$FRB)))]>,<BR> Requires<[FPContractions]>;<BR>
<BR>
Now I wrote a little toy program that, when compiled, uses this instruction.<BR>Here is the program:<BR>
#include<stdio.h><BR>
int main()<BR>{<BR> float a,b,c;<BR> b = b * c;<BR> a = a - b;<BR> return 0;<BR>}<BR>
<BR>And here is the assembly:<BR>
<BR><Insert the pPPC assembly here><BR> .text<BR> .global main<BR> .type main, @function<BR> .align 2<BR>main:<BR> lfs 0, -8(1)<BR> lfs 1, -12(1)<BR> li 3, 0<BR> fmuls 2, 1, 0<BR> stfs 2, -12(1)<BR> lfs 2, -16(1)<BR> fnmsubs 0, 1, 0, 2<BR> stfs 0, -16(1)<BR> stw 3, -20(1)<BR> stw 3, -4(1)<BR>BB1_1: # return<BR> lwz 3, -4(1)<BR> blr <BR> .size main,.-main<BR>
<BR>
At a glance, it looks right. Line 12 is, indeed the "fnmsubs" command, so <BR>the pattern did work. But look at Line 9. Here we see that the "fmuls" <BR>also happened! In effect, this means that the fmul happens TWICE.<BR>
<BR>
That can't be right can it? Unfortunately, I don't have a PPC emulator, <BR>so I can't run the code and see if it actually works or not. <BR>But it does not look right to me.<BR>
<BR>
It is a problem, right? Is there any solution? Because I would like to <BR>also use multiple-IR patterns, for the backend I am working on.<BR>
<BR>
Thank you for your assistance,<BR>Kao Chang<BR><BR><br /><hr />下載 Windows Live Messenger 9.0,多元溝通、盡情分享,和即時通訊好友線上同樂!— <a href='http://download.live.com/messenger' target='_new'>立即下載</a></body>
</html>