[Libclc-dev] [bug-fix] add_sat cannot handle type larger than i8 correctly.

Lei Mou lei.mou.uu at gmail.com
Fri Jun 1 23:31:58 PDT 2012


Hi Peter,

Thank you for your work, my work benefit a lot from libclc. During my
attempt to implement sub_sat, I found a bug in function add_sat. It cannot
handle arguments larger than char correctly. Here is an example founded in
builtins.link.bc:

define ptx_device i64 @_Z7add_satll(i64 %x, i64 %y) nounwind alwaysinline {
entry:
  %call = tail call ptx_device i8 bitcast (i64 (i64, i64)*
@__clc_add_sat_s64 to i8 (i64, i64)*)(i64 %x, i64 %y) nounwind  <-- return
type of i64 is explicitly converted to i8
  %conv = sext i8 %call to i64
  ret i64 %conv
}

The bug stems from the declarations in add_sat.cl, where the return type of
all add_sat function is declared as "char". Here is a patch fixing this bug
by simply changing the return type of each function declaration to the same
type as their parameters. Patch for sub_sat will be sent in another mail.
:-)

Regards,
Lei Mou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libclc-dev/attachments/20120602/af0eb669/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add_sat_cl.diff
Type: application/octet-stream
Size: 1082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libclc-dev/attachments/20120602/af0eb669/attachment-0002.obj>


More information about the Libclc-dev mailing list