diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py new file mode 120000 --- /dev/null +++ b/.ycm_extra_conf.py @@ -0,0 +1 @@ +/Users/jlebar/code/conf/ycm-configs/llvm \ No newline at end of file diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h --- a/llvm/include/llvm/ADT/bit.h +++ b/llvm/include/llvm/ADT/bit.h @@ -22,23 +22,31 @@ // This implementation of bit_cast is different from the C++17 one in two ways: // - It isn't constexpr because that requires compiler support. // - It requires trivially-constructible To, to avoid UB in the implementation. -template ::type +template < + typename To, typename From, + typename = typename std::enable_if::type #if (__has_feature(is_trivially_constructible) && defined(_LIBCPP_VERSION)) || \ (defined(__GNUC__) && __GNUC__ >= 5) - , typename = typename std::is_trivially_constructible::type + , + typename = typename std::enable_if< + std::is_trivially_constructible::value>::type #elif __has_feature(is_trivially_constructible) - , typename = typename std::enable_if<__is_trivially_constructible(To)>::type + , + typename = typename std::enable_if<__is_trivially_constructible(To)>::type #else // See comment below. #endif #if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \ (defined(__GNUC__) && __GNUC__ >= 5) - , typename = typename std::enable_if::value>::type - , typename = typename std::enable_if::value>::type + , + typename = + typename std::enable_if::value>::type, + typename = + typename std::enable_if::value>::type #elif __has_feature(is_trivially_copyable) - , typename = typename std::enable_if<__is_trivially_copyable(To)>::type - , typename = typename std::enable_if<__is_trivially_copyable(From)>::type + , + typename = typename std::enable_if<__is_trivially_copyable(To)>::type, + typename = typename std::enable_if<__is_trivially_copyable(From)>::type #else // This case is GCC 4.x. clang with libc++ or libstdc++ never get here. Unlike // llvm/Support/type_traits.h's is_trivially_copyable we don't want to @@ -46,7 +54,7 @@ // compilation failures on the bots instead of locally. That's acceptable // because it's very few developers, and only until we move past C++11. #endif -> + > inline To bit_cast(const From &from) noexcept { To to; std::memcpy(&to, &from, sizeof(To)); diff --git a/testcases/mul.ll b/testcases/mul.ll new file mode 100644 --- /dev/null +++ b/testcases/mul.ll @@ -0,0 +1,5 @@ +define i32 @test(i32 %x, i1 zeroext %b) { + %factor = select i1 %b, i32 8, i32 64 + %ret = mul nsw i32 %x, %factor + ret i32 %ret +} diff --git a/testcases/run-test b/testcases/run-test new file mode 100644 --- /dev/null +++ b/testcases/run-test @@ -0,0 +1,11 @@ +echo "core2" +llvm-run llc < testcases/shift-regression.ll -mtriple=i386-apple-darwin10 --x86-asm-syntax=intel | llvm-run llvm-mca -mcpu=core2 |& grep '^Total Cycles' +llvm-run llc < testcases/shift-regression.ll -mtriple=amd64-apple-darwin10 --x86-asm-syntax=intel | llvm-run llvm-mca -mcpu=core2 |& grep '^Total Cycles' + +echo "westmere" +llvm-run llc < testcases/shift-regression.ll -mtriple=i386-apple-darwin10 --x86-asm-syntax=intel | llvm-run llvm-mca -mcpu=westmere |& grep '^Total Cycles' +llvm-run llc < testcases/shift-regression.ll -mtriple=amd64-apple-darwin10 --x86-asm-syntax=intel | llvm-run llvm-mca -mcpu=westmere |& grep '^Total Cycles' + +echo "haswell" +llvm-run llc < testcases/shift-regression.ll -mtriple=i386-apple-darwin10 --x86-asm-syntax=intel | llvm-run llvm-mca -mcpu=haswell |& grep '^Total Cycles' +llvm-run llc < testcases/shift-regression.ll -mtriple=amd64-apple-darwin10 --x86-asm-syntax=intel | llvm-run llvm-mca -mcpu=haswell |& grep '^Total Cycles' diff --git a/testcases/shift-regression.ll b/testcases/shift-regression.ll new file mode 100644 --- /dev/null +++ b/testcases/shift-regression.ll @@ -0,0 +1,5 @@ +define i32 @trunc_select_miscompile(i32 %a, i1 zeroext %cc) { + %tmp1 = select i1 %cc, i32 3, i32 2 + %tmp2 = shl i32 %a, %tmp1 + ret i32 %tmp2 +} diff --git a/testcases/shl.ll b/testcases/shl.ll new file mode 100644 --- /dev/null +++ b/testcases/shl.ll @@ -0,0 +1,5 @@ +define i32 @foo(i32 %x, i1 zeroext %b) { + %factor = select i1 %b, i32 3, i32 6 + %ret = shl i32 %x, %factor + ret i32 %ret +} diff --git a/testcases/shl2.ll b/testcases/shl2.ll new file mode 100644 --- /dev/null +++ b/testcases/shl2.ll @@ -0,0 +1,6 @@ +define i32 @foo(i32 %x, i1 zeroext %cond) { + %a = shl i32 %x, 3 + %b = shl i32 %x, 6 + %ret = select i1 %cond, i32 %a, i32 %b + ret i32 %ret +}