[llvm-bugs] [Bug 50569] New: Result of __builtin_ctzs() and __tzcnt_u16() not matching after 2af95a52

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 3 02:57:58 PDT 2021


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

            Bug ID: 50569
           Summary: Result of __builtin_ctzs() and __tzcnt_u16() not
                    matching after 2af95a52
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: douglas_yung at playstation.sony.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

We have an internal test that attempts to verify intrinsics are working
correctly, and the test for __tzcnt_u16 started to fail after upstream commit
2af95a527580333940333c532679356d99b88e3d. I have extracted the following repro
which should demonstrate the issue when compiled with "-mavx -mbmi -O3":

/* test.cpp */
#include <x86intrin.h>
#include <stdio.h>

typedef union { 
    double  d64;
    short   i16;
} _data2;

int main(int argc, char *argv[]) {
    _data2 v1, v2;
    v1.d64 = v2.d64 = (short) rand();
    printf("Original: v1.d64 = %lf\n", v1.d64);
    printf("Original: v1.i16 = %d\n", (short) v1.d64);

    v1.i16 = __builtin_ctzs( v1.i16 );
    printf("__builtin_ctzs( v1.i16 ): %lf\n", v1.d64);

    v2.i16 = __tzcnt_u16( v2.i16 );
    printf("__tzcnt_u16( v2.i16 ): %lf\n", v2.d64);

    if( v1.d64 != v2.d64 ) {
        printf("Difference detected: v1.d64 = %lf, v2.d64 = %lf\n", v1.d64,
v2.d64);
        printf("Difference detected: v1.i16 = 0x%x, v2.i16 = 0x%x\n", v1.i16,
v2.i16);
        printf("Test failed\n");
        return 1;
    }

    printf("Test passed\n");
    return 0;
}
/* End test.cpp */

Here is a link comparing the generated assembly/run output for clang 12
(d28af7c65) vs. trunk (b2c8bcbab) on godbolt: https://godbolt.org/z/44T7eT3e6

When the version compiled by clang 12 is run, it produces the following output:

Original: v1.d64 = 17767.000000
Original: v1.i16 = 17767
__builtin_ctzs( v1.i16 ): 17767.000000
__tzcnt_u16( v2.i16 ): 17767.000000
Test passed

When the version compiled by clang trunk is run, it produces the following
output:

Original: v1.d64 = 17767.000000
Original: v1.i16 = 17767
__builtin_ctzs( v1.i16 ): 17767.000000
__tzcnt_u16( v2.i16 ): 17767.000000
Difference detected: v1.d64 = 17767.000000, v2.d64 = 17767.000000
Difference detected: v1.i16 = 0x20, v2.i16 = 0x10
Test failed

Bisecting this issue pointed to commit 2af95a527580333940333c532679356d99b88e3d
as the cause of this issue.

-- 
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/20210603/9f18fe2d/attachment.html>


More information about the llvm-bugs mailing list