https://bugs.llvm.org/show_bug.cgi?id=44110

            Bug ID: 44110
           Summary: Optimizer for __builtin_bswap32 fails
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: ditlef.mart...@gmail.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

The following code runs OK in Compiler Explorer with opts: -std=c++11 -O1
Fails running: -std=c++11 -O3
Byte swapping is omitted.

#include <cstdint>
#include <cstdlib>

#include <iostream>

inline
static void swap(uint32_t & value)
{
    value = __builtin_bswap32(value);
}

inline
void swap(float & value)
{
    swap(*(reinterpret_cast<uint32_t*>(&value)));
}

// Swap an array of values
template<typename PtrType>
inline void swap(PtrType * data, size_t length)
{
    for (size_t i = 0; i < length; ++i)
        swap(data[i]);
}


template<typename T>
void output(const char * s, T v) // __attribute__((noinline))
{
  std::cout << s << ": " << v << std::endl;
}

int main()
{
    float vec1[2];
    vec1[0] = rand(); vec1[1] = rand();
    const float vec1Orig = vec1[0];
    output("vec1[0] value before swap", vec1[0]);
    swap(vec1, 2);
    if (vec1[0] == vec1Orig)
        output("Failed: vec1[0] value after swap", vec1[0]);
    else
        output("OK: vec1[0] value after swap", vec1[0]);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to