[llvm-bugs] [Bug 44110] New: Optimizer for __builtin_bswap32 fails
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 21 23:33:28 PST 2019
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: unassignedclangbugs at nondot.org
Reporter: ditlef.martens at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191122/b523b6f8/attachment-0001.html>
More information about the llvm-bugs
mailing list