Last active
April 10, 2024 20:02
-
-
Save nickdesaulniers/8f20bea3bcdd9fe97219428ab6e8bf8b to your computer and use it in GitHub Desktop.
A test file I was using while trying to fix https://github.com/llvm/llvm-project/issues/20571. It tries to forcibly cause register exhaustion by using inline asm which clobbers all GPRs. In these cases, "rm" contrained operands should fall back to "m" rather than fail to compile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // -Wno-asm-operand-widths | |
| // void input_pressure(int x) { | |
| // // asm ("# %0"::"m"(x):"r0","r1","r2","r3","r12","lr","r4","r5","r6","r7","r8","r9","r10","r11"); | |
| // asm (""::"m"(x)); | |
| // } | |
| struct foo { | |
| long a, b, c, d, e; | |
| }; | |
| int zzz (struct foo my_foo) { | |
| // void zzz (struct foo my_foo) { | |
| // for i in $(seq 0 31); do echo -n "\"r$i\","; done | |
| #ifdef __hexagon__ | |
| asm ("# %0"::"rm"(my_foo.b):"r0","r1","r2","r3","r4","r5","r6","r7","r8","r9","r12","r13","r14","r15","r28","r10","r11","r16","r17","r18","r19","r20","r21","r22","r23","r24","r25","r26","r27"); | |
| #endif | |
| #ifdef __x86_64__ | |
| // int x = 42; | |
| // asm ("# %0"::"m"(x)); | |
| asm ("# %0 %1"::"rm"(my_foo.b),"rm"(my_foo.d):"ax","cx","dx","si","di","r8","r9","r10","r11","bx","bp","r14","r15","r12","r13"); | |
| asm ("# %0 %1":"=rm"(my_foo.b),"=rm"(my_foo.d)::"ax","cx","dx","si","di","r8","r9","r10","r11","bx","bp","r14","r15","r12","r13"); | |
| asm ("# %0 %1":"+rm"(my_foo.b),"+rm"(my_foo.d)::"ax","cx","dx","si","di","r8","r9","r10","r11","bx","bp","r14","r15","r12","r13"); | |
| // return my_foo.d; | |
| asm ("# %0"::"rm"(my_foo.b)); | |
| asm ("# %0 %1"::"rm"(my_foo.b), "r"(my_foo.d)); | |
| asm ("# %0":"=rm"(my_foo.b)); | |
| asm ("# %0":"+rm"(my_foo.b)); | |
| // asm volatile ("# %0":"=r"(my_foo.b):"0"(my_foo.b)); | |
| #endif | |
| #ifdef __i386__ | |
| asm ("# %0"::"rm"(my_foo.b):"ax","cx","dx","si","di","bx","bp"); | |
| asm ("# %0":"=rm"(my_foo.b)::"ax","cx","dx","si","di","bx","bp"); | |
| asm ("# %0":"+rm"(my_foo.b)::"ax","cx","dx","si","di","bx","bp"); | |
| #endif | |
| #ifdef __lanai__ | |
| asm (""::"rm"(my_foo.b):"r0","r1","r2","r3","r4","r5","r6","r7","r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18","r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29","r30","r31"); | |
| #endif | |
| #ifdef __NVPTX__ | |
| // asm ("# %0 "::"rm"(my_foo.b):"r1"); | |
| #endif | |
| // TODO: something fishy is going on for ARM. | |
| #ifdef __arm__ | |
| // int x = 42; | |
| // asm ("# %0"::"m"(x)); | |
| // asm ("# %0"::"rm"(my_foo.b):"r0","r1","r2","r3","r12","lr","r4","r5","r6","r7","r8","r9","r10","r11"); | |
| asm ("# %0 %1"::"rm"(my_foo.b),"rm"(my_foo.d):"r0","r1","r2","r3","r12","lr","r4","r5","r6","r7","r8","r9","r10","r11"); | |
| #endif | |
| #ifdef __aarch64__ | |
| // int x = 42; | |
| // asm ("# %0"::"m"(x)); | |
| asm ("# %0 %1"::"rm"(my_foo.b),"rm"(my_foo.d):"x8","x9","x10","x11","x12","x13","x14","x15","x16","x17","x18","x0","x1","x2","x3","x4","x5","x6","x7","x19","x20","x21","x22","x23","x24","x25","x26","x27","x28","x29","x30"); | |
| asm ("# %0 %1":"=rm"(my_foo.b),"=rm"(my_foo.d)::"x8","x9","x10","x11","x12","x13","x14","x15","x16","x17","x18","x0","x1","x2","x3","x4","x5","x6","x7","x19","x20","x21","x22","x23","x24","x25","x26","x27","x28","x29","x30"); | |
| asm ("# %0 %1":"+rm"(my_foo.b),"+rm"(my_foo.d)::"x8","x9","x10","x11","x12","x13","x14","x15","x16","x17","x18","x0","x1","x2","x3","x4","x5","x6","x7","x19","x20","x21","x22","x23","x24","x25","x26","x27","x28","x29","x30"); | |
| asm ("# %0"::"rm"(my_foo.b)); | |
| asm ("# %0 %1"::"rm"(my_foo.b), "r"(my_foo.d)); | |
| asm ("# %0":"=rm"(my_foo.b)); | |
| asm ("# %0":"+rm"(my_foo.b)); | |
| // asm ("# %0"::"rm"(my_foo.b):"x8","x9","x10","x11","x12","x13","x14","x15","x16","x17","x18","x0","x1","x2","x3","x4","x5","x6","x7","x19","x20","x21","x22","x23","x24","x25","x26","x27","x28","x29","x30"); | |
| // asm ("# %0"::"mr"(my_foo.b):"x8","x9","x10","x11","x12","x13","x14","x15","x16","x17","x18","x0","x1","x2","x3","x4","x5","x6","x7","x19","x20","x21","x22","x23","x24","x25","x26","x27","x28","x29","x30"); | |
| #endif | |
| #ifdef __powerpc64__ | |
| // TODO: only long works, not int | |
| asm ("# %0 %1"::"rm"(my_foo.b),"rm"(my_foo.d):"r4","r5","r6","r7","r8","r9","r10","r11","r12","r0","r30","r29","r28","r27","r26","r25","r24","r23","r22","r21","r20","r19","r18","r17","r16","r15","r14","r31","r3"); | |
| // long x = 42; | |
| // asm ("# %0"::"m"(x)); | |
| #endif | |
| #ifdef __riscv | |
| // int x = 42; | |
| // asm ("# %0"::"m"(x)); | |
| asm ("# %0 %1"::"rm"(my_foo.b), "rm"(my_foo.d):"a1","a2","a3","a4","a5","a6","a7","t0","t1","t2","t3","t4","t5","t6","s0","s1","s2","s3","s4","s5","s6","s7","s8","s9","s10","s11","ra"); | |
| #endif | |
| return my_foo.a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment