Instruction Implementation

hi all

I have a question about implementing a new instruction which does this
function f(x) = x + ceilf (x) .x is a single float
i have already added the instruction in my backend in the .td file

def SUBCEIL_S : FFR<0x11, 0x3, 16, (outs FGR32:$fd), (ins FGR32:$fs),
"frac.s\t$fd, $fs", [(set (f32 FGR32:$fd), (fadd (f32 FGR32:$fs ),(f32
(ceilf FGR32:$fs))))] >;
it makes and install correctly but when i ll try to write code to use this
instruction there is no luck.

Should i do something in ISelLowering.cpp or ISelDAGToDAG.cpp file? my
backend is based on mips backend

thanks in Advance,

Stavropoulos Nikos

Hi,

def SUBCEIL_S : FFR<0x11, 0x3, 16, (outs FGR32:$fd), (ins FGR32:$fs),
"frac.s\t$fd, $fs", [(set (f32 FGR32:$fd), (fadd (f32 FGR32:$fs ),(f32
(ceilf FGR32:$fs))))] >;

it makes and install correctly but when i ll try to write code to use this
instruction there is no luck.

More details (including the .ll source and *how* exactly things are
going wrong) would be useful. Does llc crash? Does it simply not
select your code even though there's an fceil in the DAG? Is there no
fceil node in the DAG (run llc with "-view-isel-dags")?

Assuming the "ceilf" is a typo, my wild stab in the dark would be that
you've got code something like:

define float @foo(float %in) {
  %1 = tail call float @ceilf(float %in)
  ret float %1
}

declare float @ceilf(float)

and haven't given the "@ceilf" function the attribute "readonly". This
is what LLVM uses (in many cases) to decide whether the call is a
known library call and can be transformed into an appropriate ISD
node.

Tim.

Hi and thanks for answering

llc works fine just does not selecting my instruction

i ve uploaded .ll file

how can i include this attribute "readonly" so i can see if changes the
generated assembly?

my code is very simple
int main (){
float d, d1 ;
        d= 12.3;
        d1 = d - ceilf(d);

return 0;
}

Hi,

i ve uploaded .ll file

Is that the C file that's at the end of your message? To produce a .ll
file, you give clang the "-emit-llvm" option (and probably "-S").

Anyway, what I see in the C you posted is that Clang is using constant
folding to avoid doing any of the operations you've requested. A
better C file test would be:

float foo(float d) {
  return d - ceilf(d);
}

For me LLVM does use the FCEIL node in that case (it doesn't know what
d is so can't optimise your operations away). I'm still a little
worried that ceilf isn't declared, but LLVM seems to do the "right"
thing anyway.

I'm also a little worried that your pattern has fadd, but your C
source has a subtraction.

how can i include this attribute "readonly" so i can see if changes the
generated assembly?

The best documentation is probably the "Function Attributes" section
in http://llvm.org/docs/LangRef.html, but it doesn't look like you've
been using LLVM IR so that may not be immediately useful.

Cheers.

Tim.

I'm also a little worried that your pattern has fadd, but your C
source has a subtraction.

:S i wrote it wrong the true implementation is
def SUBCEIL_S : FFR<0x11, 0x3, 16, (outs FGR32:$fd), (ins FGR32:$fs),
"frac.s\t$fd, $fs", [(set (f32 FGR32:$fd), (fsub (f32 FGR32:$fs ),(f32
(ceilf FGR32:$fs))))] >;

I use some C,C++ code to test my backend.

i use clang with those argument

-m32 -emit-llvm -S -target mipsel-linux-gnu -I..
and i have tried to add this in case so it will not use standard libs
-nostdlib -nostdinc -fno-builtin but with no luck

attached the new .ll for code

#include "math.h"
float foo (float x)
{

        return (x - ceilf(x));
}
int main()
{
float d, d1 ;
        d= 12.3f;
        d1= foo(d);
    return 0;
}

test.ll <http://llvm.1065342.n5.nabble.com/file/n56383/test.ll>

Hi,

#include "math.h"

[...]

declare float @_Z8ff_ceilff(float)

It looks like your math.h is not declaring "ceilf" with C language
linkage (i.e. 'extern "C"') so it's getting name-mangled (and in an
extremely odd way I'm not familiar with, unless your math.h contains
"#define ceilf ff_ceilf" -- which would also be bad); this means LLVM
can't recognise it as the ceiling function and just assumes it's some
unknown call.

What you're looking for is:
    declare float @ceilf(float)
being given a set of attributes almost certainly including "readnone"
(though "readonly" would be sufficient).

Cheers.

Tim.