[llvm-bugs] [Bug 34549] New: [miscompilation] set to 0 on __m128d ignored: garbage in high element on compare and movemask

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 11 04:09:09 PDT 2017


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

            Bug ID: 34549
           Summary: [miscompilation] set to 0 on __m128d ignored: garbage
                    in high element on compare and movemask
           Product: new-bugs
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: kretz at kde.org
                CC: llvm-bugs at lists.llvm.org

reduced testcase:

#include <x86intrin.h>
#include <iostream>

std::ostream &operator<<(std::ostream &s, __m128d v)
{
    return s << '{' << v[0] << ", " << v[1] << '}';
}

int main()
{
    for (double lo_ : {1., 1.}) {
        for (double hi_ : {1., 1.}) {
            for (std::size_t pos = 0; pos < 2; ++pos) {
                __m128d lo = _mm_set1_pd(lo_);
                __m128d hi = _mm_set1_pd(hi_);
                if (0 != _mm_movemask_pd(hi < lo)) {
                    std::cerr << hi << ", lo: " << lo;
                    if (3 != _mm_movemask_pd(hi >= hi)) {
                        std::cerr << hi << ", lo: " << lo;
                    }
                }
            }
        }
    }

    __m128d x = _mm_set1_pd(1.);
    for (std::size_t i = 0; i < 2; ++i) {
        asm("ror $64,%%rax" ::"m"(x));
        x[i] = 0;  // #1
    }
    asm("ror $64,%%rax" :"+m"(x));
    if (3 != _mm_movemask_pd(x == _mm_setzero_pd())) {
        std::cerr << "!!!FAILED!!!\n";
        return 1;
    }
    return 0;
}

Compile with `clang++-5.0 -std=c++14 -O2 -msse2`. clang 4.0 does not fail.

The assignment at line #1 is skipped for i = 1. However, minimal changes to
unrelated code lead to the use of a `movsd` from memory, thus zeroing the upper
64 bits, as requested.

The above code is a reduced testcase from a unit test in
https://github.com/VcDevel/Vc.

-- 
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/20170911/dbabc690/attachment.html>


More information about the llvm-bugs mailing list