[llvm-dev] Endianness for multi-word types

Tim Shen via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 30 19:17:52 PST 2015


Hi,

I'm recently trying to investigate ppc_fp128 related problem. Here is a
minimal C++ test case that seems wrongly compiled:

long double id(long double a) {
  return a;
}
bool f(long double x) {
  return id(__builtin_fabsl(x)) >= 0;
}
int main() {
  if (f(-123.l)) {
    return 0;
  }
  return 1;
}

The program compiled with command:
clang++ -static -target powerpc64le-linux-gnu bad.cc
Returns 1 on a ppc machine.

I did some investigation, it turns out
in lib/CodeGen/SelectionDAG/DAGCombiner.cpp, a combination is wrongly
assuming the endianness for the i128 bitcasted from a ppc_fp128 (two
doubles bit-concatenated together):
  // fold (bitconvert (fabs x)) -> (and (bitconvert x), (not signbit))

This reveals that endianness conversion concerning ppc_fp128 or i128, and
big-endian or little-endian target is too confusing to me.

I can certainly fix this case by using a "smarter signbit" (e.g.
0x00000000000000001000000000000000), but this seems more confusing. I
wonder if anyone has the best background knowledge here?

Background I found:
http://llvm.org/klaus/llvm/commit/1ef2cec146099f4bf46c31b913c7f1538935a867/

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151201/2faf9268/attachment.html>


More information about the llvm-dev mailing list