brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.1 KiB · 4877d15 Raw
280 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=i386-linux-gnu -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=X86-ALL,X86-GOOD-RA3; RUN: llc -mtriple=i386-linux-gnu -verify-machineinstrs -pre-RA-sched=fast %s -o - | FileCheck %s --check-prefixes=X86-ALL,X86-FAST-RA4 5; RUN: llc -mtriple=x86_64-linux-gnu -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=X64-ALL6; RUN: llc -mtriple=x86_64-linux-gnu -verify-machineinstrs -pre-RA-sched=fast %s -o - | FileCheck %s --check-prefix=X64-ALL7; RUN: llc -mtriple=x86_64-linux-gnu -verify-machineinstrs -mattr=+sahf %s -o - | FileCheck %s --check-prefix=X64-ALL8; RUN: llc -mtriple=x86_64-linux-gnu -verify-machineinstrs -mattr=+sahf -pre-RA-sched=fast %s -o - | FileCheck %s --check-prefix=X64-ALL9; RUN: llc -mtriple=x86_64-linux-gnu -verify-machineinstrs -mcpu=corei7 %s -o - | FileCheck %s --check-prefix=X64-ALL10 11declare i32 @foo()12declare i32 @bar(i64)13 14; In the following case when using fast scheduling we get a long chain of15; EFLAGS save/restore due to a sequence of:16; cmpxchg8b (implicit-def eflags)17; eax = copy eflags18; adjcallstackdown3219; ...20; use of eax21; During PEI the adjcallstackdown32 is replaced with the subl which22; clobbers eflags, effectively interfering in the liveness interval. However,23; we then promote these copies into independent conditions in GPRs that avoids24; repeated saving and restoring logic and can be trivially managed by the25; register allocator.26define i64 @test_intervening_call(ptr %foo, i64 %bar, i64 %baz) nounwind {27; X86-GOOD-RA-LABEL: test_intervening_call:28; X86-GOOD-RA:       # %bb.0: # %entry29; X86-GOOD-RA-NEXT:    pushl %ebx30; X86-GOOD-RA-NEXT:    pushl %esi31; X86-GOOD-RA-NEXT:    pushl %eax32; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %eax33; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %edx34; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %ebx35; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %ecx36; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %esi37; X86-GOOD-RA-NEXT:    lock cmpxchg8b (%esi)38; X86-GOOD-RA-NEXT:    setne %bl39; X86-GOOD-RA-NEXT:    subl $8, %esp40; X86-GOOD-RA-NEXT:    pushl %edx41; X86-GOOD-RA-NEXT:    pushl %eax42; X86-GOOD-RA-NEXT:    calll bar@PLT43; X86-GOOD-RA-NEXT:    addl $16, %esp44; X86-GOOD-RA-NEXT:    testb %bl, %bl45; X86-GOOD-RA-NEXT:    jne .LBB0_346; X86-GOOD-RA-NEXT:  # %bb.1: # %t47; X86-GOOD-RA-NEXT:    movl $42, %eax48; X86-GOOD-RA-NEXT:    jmp .LBB0_249; X86-GOOD-RA-NEXT:  .LBB0_3: # %f50; X86-GOOD-RA-NEXT:    xorl %eax, %eax51; X86-GOOD-RA-NEXT:  .LBB0_2: # %t52; X86-GOOD-RA-NEXT:    xorl %edx, %edx53; X86-GOOD-RA-NEXT:    addl $4, %esp54; X86-GOOD-RA-NEXT:    popl %esi55; X86-GOOD-RA-NEXT:    popl %ebx56; X86-GOOD-RA-NEXT:    retl57;58; X86-FAST-RA-LABEL: test_intervening_call:59; X86-FAST-RA:       # %bb.0: # %entry60; X86-FAST-RA-NEXT:    pushl %ebx61; X86-FAST-RA-NEXT:    pushl %esi62; X86-FAST-RA-NEXT:    pushl %eax63; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %esi64; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %ebx65; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %ecx66; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %eax67; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %edx68; X86-FAST-RA-NEXT:    lock cmpxchg8b (%esi)69; X86-FAST-RA-NEXT:    setne %bl70; X86-FAST-RA-NEXT:    subl $8, %esp71; X86-FAST-RA-NEXT:    pushl %edx72; X86-FAST-RA-NEXT:    pushl %eax73; X86-FAST-RA-NEXT:    calll bar@PLT74; X86-FAST-RA-NEXT:    addl $16, %esp75; X86-FAST-RA-NEXT:    testb %bl, %bl76; X86-FAST-RA-NEXT:    jne .LBB0_377; X86-FAST-RA-NEXT:  # %bb.1: # %t78; X86-FAST-RA-NEXT:    movl $42, %eax79; X86-FAST-RA-NEXT:    jmp .LBB0_280; X86-FAST-RA-NEXT:  .LBB0_3: # %f81; X86-FAST-RA-NEXT:    xorl %eax, %eax82; X86-FAST-RA-NEXT:  .LBB0_2: # %t83; X86-FAST-RA-NEXT:    xorl %edx, %edx84; X86-FAST-RA-NEXT:    addl $4, %esp85; X86-FAST-RA-NEXT:    popl %esi86; X86-FAST-RA-NEXT:    popl %ebx87; X86-FAST-RA-NEXT:    retl88;89; X64-ALL-LABEL: test_intervening_call:90; X64-ALL:       # %bb.0: # %entry91; X64-ALL-NEXT:    pushq %rbx92; X64-ALL-NEXT:    movq %rsi, %rax93; X64-ALL-NEXT:    lock cmpxchgq %rdx, (%rdi)94; X64-ALL-NEXT:    setne %bl95; X64-ALL-NEXT:    movq %rax, %rdi96; X64-ALL-NEXT:    callq bar@PLT97; X64-ALL-NEXT:    testb %bl, %bl98; X64-ALL-NEXT:    jne .LBB0_299; X64-ALL-NEXT:  # %bb.1: # %t100; X64-ALL-NEXT:    movl $42, %eax101; X64-ALL-NEXT:    popq %rbx102; X64-ALL-NEXT:    retq103; X64-ALL-NEXT:  .LBB0_2: # %f104; X64-ALL-NEXT:    xorl %eax, %eax105; X64-ALL-NEXT:    popq %rbx106; X64-ALL-NEXT:    retq107entry:108  %cx = cmpxchg ptr %foo, i64 %bar, i64 %baz seq_cst seq_cst109  %v = extractvalue { i64, i1 } %cx, 0110  %p = extractvalue { i64, i1 } %cx, 1111  call i32 @bar(i64 %v)112  br i1 %p, label %t, label %f113 114t:115  ret i64 42116 117f:118  ret i64 0119}120 121; Interesting in producing a clobber without any function calls.122define i32 @test_control_flow(ptr %p, i32 %i, i32 %j) nounwind {123; X86-ALL-LABEL: test_control_flow:124; X86-ALL:       # %bb.0: # %entry125; X86-ALL-NEXT:    movl {{[0-9]+}}(%esp), %eax126; X86-ALL-NEXT:    cmpl {{[0-9]+}}(%esp), %eax127; X86-ALL-NEXT:    jle .LBB1_6128; X86-ALL-NEXT:  # %bb.1: # %loop_start129; X86-ALL-NEXT:    movl {{[0-9]+}}(%esp), %ecx130; X86-ALL-NEXT:    .p2align 4131; X86-ALL-NEXT:  .LBB1_2: # %while.condthread-pre-split.i132; X86-ALL-NEXT:    # =>This Loop Header: Depth=1133; X86-ALL-NEXT:    # Child Loop BB1_3 Depth 2134; X86-ALL-NEXT:    movl (%ecx), %edx135; X86-ALL-NEXT:    .p2align 4136; X86-ALL-NEXT:  .LBB1_3: # %while.cond.i137; X86-ALL-NEXT:    # Parent Loop BB1_2 Depth=1138; X86-ALL-NEXT:    # => This Inner Loop Header: Depth=2139; X86-ALL-NEXT:    movl %edx, %eax140; X86-ALL-NEXT:    xorl %edx, %edx141; X86-ALL-NEXT:    testl %eax, %eax142; X86-ALL-NEXT:    je .LBB1_3143; X86-ALL-NEXT:  # %bb.4: # %while.body.i144; X86-ALL-NEXT:    # in Loop: Header=BB1_2 Depth=1145; X86-ALL-NEXT:    lock cmpxchgl %eax, (%ecx)146; X86-ALL-NEXT:    jne .LBB1_2147; X86-ALL-NEXT:  # %bb.5:148; X86-ALL-NEXT:    xorl %eax, %eax149; X86-ALL-NEXT:  .LBB1_6: # %cond.end150; X86-ALL-NEXT:    retl151;152; X64-ALL-LABEL: test_control_flow:153; X64-ALL:       # %bb.0: # %entry154; X64-ALL-NEXT:    movl %esi, %eax155; X64-ALL-NEXT:    cmpl %edx, %esi156; X64-ALL-NEXT:    jle .LBB1_5157; X64-ALL-NEXT:    .p2align 4158; X64-ALL-NEXT:  .LBB1_1: # %while.condthread-pre-split.i159; X64-ALL-NEXT:    # =>This Loop Header: Depth=1160; X64-ALL-NEXT:    # Child Loop BB1_2 Depth 2161; X64-ALL-NEXT:    movl (%rdi), %ecx162; X64-ALL-NEXT:    .p2align 4163; X64-ALL-NEXT:  .LBB1_2: # %while.cond.i164; X64-ALL-NEXT:    # Parent Loop BB1_1 Depth=1165; X64-ALL-NEXT:    # => This Inner Loop Header: Depth=2166; X64-ALL-NEXT:    movl %ecx, %eax167; X64-ALL-NEXT:    xorl %ecx, %ecx168; X64-ALL-NEXT:    testl %eax, %eax169; X64-ALL-NEXT:    je .LBB1_2170; X64-ALL-NEXT:  # %bb.3: # %while.body.i171; X64-ALL-NEXT:    # in Loop: Header=BB1_1 Depth=1172; X64-ALL-NEXT:    lock cmpxchgl %eax, (%rdi)173; X64-ALL-NEXT:    jne .LBB1_1174; X64-ALL-NEXT:  # %bb.4:175; X64-ALL-NEXT:    xorl %eax, %eax176; X64-ALL-NEXT:  .LBB1_5: # %cond.end177; X64-ALL-NEXT:    retq178entry:179  %cmp = icmp sgt i32 %i, %j180  br i1 %cmp, label %loop_start, label %cond.end181 182loop_start:183  br label %while.condthread-pre-split.i184 185while.condthread-pre-split.i:186  %.pr.i = load i32, ptr %p, align 4187  br label %while.cond.i188 189while.cond.i:190  %0 = phi i32 [ %.pr.i, %while.condthread-pre-split.i ], [ 0, %while.cond.i ]191  %tobool.i = icmp eq i32 %0, 0192  br i1 %tobool.i, label %while.cond.i, label %while.body.i193 194while.body.i:195  %.lcssa = phi i32 [ %0, %while.cond.i ]196  %1 = cmpxchg ptr %p, i32 %.lcssa, i32 %.lcssa seq_cst seq_cst197  %2 = extractvalue { i32, i1 } %1, 1198  br i1 %2, label %cond.end.loopexit, label %while.condthread-pre-split.i199 200cond.end.loopexit:201  br label %cond.end202 203cond.end:204  %cond = phi i32 [ %i, %entry ], [ 0, %cond.end.loopexit ]205  ret i32 %cond206}207 208; This one is an interesting case because CMOV doesn't have a chain209; operand. Naive attempts to limit cmpxchg EFLAGS use are likely to fail here.210define i32 @test_feed_cmov(ptr %addr, i32 %desired, i32 %new) nounwind {211; X86-GOOD-RA-LABEL: test_feed_cmov:212; X86-GOOD-RA:       # %bb.0: # %entry213; X86-GOOD-RA-NEXT:    pushl %ebx214; X86-GOOD-RA-NEXT:    pushl %esi215; X86-GOOD-RA-NEXT:    pushl %eax216; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %eax217; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %esi218; X86-GOOD-RA-NEXT:    movl {{[0-9]+}}(%esp), %ecx219; X86-GOOD-RA-NEXT:    lock cmpxchgl %esi, (%ecx)220; X86-GOOD-RA-NEXT:    sete %bl221; X86-GOOD-RA-NEXT:    calll foo@PLT222; X86-GOOD-RA-NEXT:    testb %bl, %bl223; X86-GOOD-RA-NEXT:    jne .LBB2_2224; X86-GOOD-RA-NEXT:  # %bb.1: # %entry225; X86-GOOD-RA-NEXT:    movl %eax, %esi226; X86-GOOD-RA-NEXT:  .LBB2_2: # %entry227; X86-GOOD-RA-NEXT:    movl %esi, %eax228; X86-GOOD-RA-NEXT:    addl $4, %esp229; X86-GOOD-RA-NEXT:    popl %esi230; X86-GOOD-RA-NEXT:    popl %ebx231; X86-GOOD-RA-NEXT:    retl232;233; X86-FAST-RA-LABEL: test_feed_cmov:234; X86-FAST-RA:       # %bb.0: # %entry235; X86-FAST-RA-NEXT:    pushl %ebx236; X86-FAST-RA-NEXT:    pushl %esi237; X86-FAST-RA-NEXT:    pushl %eax238; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %ecx239; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %esi240; X86-FAST-RA-NEXT:    movl {{[0-9]+}}(%esp), %eax241; X86-FAST-RA-NEXT:    lock cmpxchgl %esi, (%ecx)242; X86-FAST-RA-NEXT:    sete %bl243; X86-FAST-RA-NEXT:    calll foo@PLT244; X86-FAST-RA-NEXT:    testb %bl, %bl245; X86-FAST-RA-NEXT:    jne .LBB2_2246; X86-FAST-RA-NEXT:  # %bb.1: # %entry247; X86-FAST-RA-NEXT:    movl %eax, %esi248; X86-FAST-RA-NEXT:  .LBB2_2: # %entry249; X86-FAST-RA-NEXT:    movl %esi, %eax250; X86-FAST-RA-NEXT:    addl $4, %esp251; X86-FAST-RA-NEXT:    popl %esi252; X86-FAST-RA-NEXT:    popl %ebx253; X86-FAST-RA-NEXT:    retl254;255; X64-ALL-LABEL: test_feed_cmov:256; X64-ALL:       # %bb.0: # %entry257; X64-ALL-NEXT:    pushq %rbp258; X64-ALL-NEXT:    pushq %rbx259; X64-ALL-NEXT:    pushq %rax260; X64-ALL-NEXT:    movl %edx, %ebx261; X64-ALL-NEXT:    movl %esi, %eax262; X64-ALL-NEXT:    lock cmpxchgl %edx, (%rdi)263; X64-ALL-NEXT:    sete %bpl264; X64-ALL-NEXT:    callq foo@PLT265; X64-ALL-NEXT:    testb %bpl, %bpl266; X64-ALL-NEXT:    cmovnel %ebx, %eax267; X64-ALL-NEXT:    addq $8, %rsp268; X64-ALL-NEXT:    popq %rbx269; X64-ALL-NEXT:    popq %rbp270; X64-ALL-NEXT:    retq271entry:272  %res = cmpxchg ptr %addr, i32 %desired, i32 %new seq_cst seq_cst273  %success = extractvalue { i32, i1 } %res, 1274 275  %rhs = call i32 @foo()276 277  %ret = select i1 %success, i32 %new, i32 %rhs278  ret i32 %ret279}280