brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 4037c1b Raw
132 lines · c
1// REQUIRES: x86-registered-target2// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O0 -emit-llvm %s -o - | FileCheck %s3// RUN: %clang_cc1 -triple i386-pc-linux-gnu -O0 -emit-llvm %s -o - | FileCheck %s4 5int test1(int cond) {6  // CHECK-LABEL: define{{.*}} i32 @test1(7  // CHECK: callbr void asm sideeffect8  // CHECK: to label %asm.fallthrough [label %label_true, label %loop]9  // CHECK-LABEL: asm.fallthrough:10  asm volatile goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);11  asm volatile goto("testl %0, %0; jne %l2;" :: "r"(cond)::label_true, loop);12  // CHECK: callbr void asm sideeffect13  // CHECK: to label %asm.fallthrough1 [label %label_true, label %loop]14  // CHECK-LABEL: asm.fallthrough1:15  return 0;16loop:17  return 0;18label_true:19  return 1;20}21 22int test2(int cond) {23  // CHECK-LABEL: define{{.*}} i32 @test2(24  // CHECK: callbr i32 asm sideeffect25  // CHECK: to label %asm.fallthrough [label %label_true.split, label %loop.split]26  // CHECK-LABEL: asm.fallthrough:27  asm volatile goto("testl %0, %0; jne %l2;" : "=r"(cond) : "r"(cond) :: label_true, loop);28  asm volatile goto("testl %0, %0; jne %l3;" : "=r"(cond) : "r"(cond) :: label_true, loop);29  // CHECK: callbr i32 asm sideeffect30  // CHECK: to label %asm.fallthrough1 [label %label_true.split2, label %loop.split3]31  // CHECK-LABEL: asm.fallthrough1:32  return 0;33loop:34  return 0;35label_true:36  return 1;37}38 39int test3(int out1, int out2) {40  // CHECK-LABEL: define{{.*}} i32 @test3(41  // CHECK: callbr { i32, i32 } asm sideeffect42  // CHECK: to label %asm.fallthrough [label %label_true.split, label %loop.split]43  // CHECK-LABEL: asm.fallthrough:44  asm volatile goto("testl %0, %0; jne %l3;" : "=r"(out1), "=r"(out2) : "r"(out1) :: label_true, loop);45  asm volatile goto("testl %0, %0; jne %l4;" : "=r"(out1), "=r"(out2) : "r"(out1) :: label_true, loop);46  // CHECK: callbr { i32, i32 } asm sideeffect47  // CHECK: to label %asm.fallthrough6 [label %label_true.split11, label %loop.split14]48  // CHECK-LABEL: asm.fallthrough6:49  return 0;50loop:51  return 0;52label_true:53  return 1;54}55 56int test4(int out1, int out2) {57  // CHECK-LABEL: define{{.*}} i32 @test4(58  // CHECK: callbr { i32, i32 } asm sideeffect "jne ${5:l}", "={si},={di},r,0,1,!i,!i59  // CHECK: to label %asm.fallthrough [label %label_true.split, label %loop.split]60  // CHECK-LABEL: asm.fallthrough:61  if (out1 < out2)62    asm volatile goto("jne %l5" : "+S"(out1), "+D"(out2) : "r"(out1) :: label_true, loop);63  else64    asm volatile goto("jne %l7" : "+S"(out1), "+D"(out2) : "r"(out1), "r"(out2) :: label_true, loop);65  // CHECK: callbr { i32, i32 } asm sideeffect "jne ${7:l}", "={si},={di},r,r,0,1,!i,!i66  // CHECK: to label %asm.fallthrough6 [label %label_true.split11, label %loop.split14]67  // CHECK-LABEL: asm.fallthrough6:68  return out1 + out2;69loop:70  return -1;71label_true:72  return -2;73}74 75int test5(int addr, int size, int limit) {76  // CHECK-LABEL: define{{.*}} i32 @test5(77  // CHECK: callbr i32 asm "add $1,$0 ; jc ${4:l} ; cmp $2,$0 ; ja ${4:l} ; ", "=r,imr,imr,0,!i78  // CHECK: to label %asm.fallthrough [label %t_err.split]79  // CHECK-LABEL: asm.fallthrough:80  asm goto(81      "add %1,%0 ; "82      "jc %l[t_err] ; "83      "cmp %2,%0 ; "84      "ja %l[t_err] ; "85      : "+r" (addr)86      : "g" (size), "g" (limit)87      : : t_err);88  return 0;89t_err:90  return 1;91}92 93int test6(int out1) {94  // CHECK-LABEL: define{{.*}} i32 @test6(95  // CHECK: callbr i32 asm sideeffect "testl $0, $0; testl $1, $1; jne ${3:l}", "={si},r,0,!i,!i,{{.*}}96  // CHECK: to label %asm.fallthrough [label %label_true.split, label %landing.split]97  // CHECK-LABEL: asm.fallthrough:98  // CHECK-LABEL: landing:99  int out2 = 42;100  asm volatile goto("testl %0, %0; testl %1, %1; jne %l3" : "+S"(out2) : "r"(out1) :: label_true, landing);101landing:102  return out1 + out2;103label_true:104  return -2;105}106 107// test7 - For the output templates in the asm string (%0, %l2), GCC places108// hidden inputs tied to outputs ("+r" constraint) BEFORE labels. Test that foo109// is $2 (or rather ${2:l} because of the l output template) in the emitted asm110// string, not $1.111void *test7(void) {112  // CHECK-LABEL: define{{.*}} ptr @test7(113  // CHECK: %1 = callbr ptr asm "# $0\0A\09# ${2:l}", "=r,0,!i,~{dirflag},~{fpsr},~{flags}"(ptr %0)114  // CHECK-NEXT: to label %asm.fallthrough [label %foo.split]115  void *p = &&foo;116  asm goto ("# %0\n\t# %l2":"+r"(p):::foo);117foo:118  return p;119}120 121// test8 - the same as test7, but this time we use symbolic names rather than122// numbered outputs.123void *test8(void) {124  // CHECK-LABEL: define{{.*}} ptr @test8(125  // CHECK: %1 = callbr ptr asm "# $0\0A\09# ${2:l}", "=r,0,!i,~{dirflag},~{fpsr},~{flags}"(ptr %0)126  // CHECK-NEXT: to label %asm.fallthrough [label %foo.split]127  void *p = &&foo;128  asm goto ("# %0\n\t# %l[foo]":"+r"(p):::foo);129foo:130  return p;131}132