| 1 |
/* { dg-options "-O2" } */ |
| 2 |
/* { dg-do run } */ |
| 3 |
|
| 4 |
/* nvptx backend used to emit lo/ls/hs/hi suffixes on unsigned comparison |
| 5 |
insns instead of the more common lt/le/ge/gt, but ptxas and PTX JIT |
| 6 |
miscompile 'ls' and 'hi' under some circumstances, such as when the first |
| 7 |
source operand expands to a constant memory load, as demonstrated below. |
| 8 |
Reported as NVIDIA bug ID 1725195 (tracker is not public). */ |
| 9 |
|
| 10 |
/* Define this to observe PTX translation breakage. */ |
| 11 |
//#define EMIT_BROKEN_ASM 1 |
| 12 |
|
| 13 |
/* Or define this to get expected codegen. */ |
| 14 |
//#define EMIT_WORKING_ASM 1 |
| 15 |
|
| 16 |
static __attribute__((noinline,noclone)) int ls(unsigned a) |
| 17 |
{ |
| 18 |
unsigned v; |
| 19 |
/* %nctaid.x is always 1 in gcc testing. */ |
| 20 |
asm ("mov.u32 %0, %%nctaid.x;" : "=r"(v)); |
| 21 |
#if defined(EMIT_BROKEN_ASM) |
| 22 |
asm ("set.u32.ls.u32 %0, %1, %0;" : "+r"(a) : "r"(v)); |
| 23 |
#elif defined(EMIT_WORKING_ASM) |
| 24 |
asm ("set.u32.le.u32 %0, %1, %0;" : "+r"(a) : "r"(v)); |
| 25 |
#else |
| 26 |
a = v <= a ? -1 : 0; |
| 27 |
#endif |
| 28 |
return a; |
| 29 |
} |
| 30 |
static __attribute__((noinline,noclone)) int hi(unsigned a) |
| 31 |
{ |
| 32 |
unsigned v; |
| 33 |
asm ("mov.u32 %0, %%nctaid.x;" : "=r"(v)); |
| 34 |
#if defined(EMIT_BROKEN_ASM) |
| 35 |
asm ("set.u32.hi.u32 %0, %1, %0;" : "+r"(a) : "r"(v)); |
| 36 |
#elif defined(EMIT_WORKING_ASM) |
| 37 |
asm ("set.u32.gt.u32 %0, %1, %0;" : "+r"(a) : "r"(v)); |
| 38 |
#else |
| 39 |
a = v > a ? -1 : 0; |
| 40 |
#endif |
| 41 |
return a; |
| 42 |
} |
| 43 |
int main() |
| 44 |
{ |
| 45 |
int i; |
| 46 |
for (i=0; i<3; i++) |
| 47 |
if (ls(i) != -(1 <= i) || hi(i) != -(1 > i)) |
| 48 |
__builtin_abort(); |
| 49 |
return 0; |
| 50 |
} |