Hi,

Moving to CLANG toolset we bumped in a problem illustrated by the following small reproducer. Reproducible with clang34, clang35, clang36 on FreeBSD 9.3 x64. It is reproducible only with -O3. The program works as expected on GCC and MSVC.

#include <stdio.h>
#include <stdint.h>

bool test_fp_lt(int64_t x) {
    // Take care of -0
    return (-x) > 0;
}

void test_lt(int64_t x, bool res) {
    bool r = test_fp_lt(x);
    if(r != res) {
printf("test_lt failed for %016lx: expected %d, got %d\n", x, res, r);
    }
}

int main() {
    test_lt(0x0000000000000000ul, false);
    test_lt(0x8000000000000000ul, false);
    test_lt(0x4000000000000000ul, false);
    test_lt(0x8000000000000001ul, true);
    test_lt(0xFFFFFFFFFFFFFFF0ul, true);
    return 0;
}

The program should not print anything. It fails for 0x8000000000000000ul, though.

The geneated code for test_fp_lt is:
shr rdi, 63
mov al, dil

whereas the expected working code (from GCC) is
neg rdi
test rdi, rdi
setg al

As far as I understand the compiler co,piler optimizes (-x) > 0 into x < 0. What is wrong here?

Best regards,
Artem

<<attachment: artem_alimarin.vcf>>

_______________________________________________
cfe-users mailing list
cfe-users@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to