CXX_FAST_TLS calling convention: fix issue on X86-64.
When we have a single basic block, the explicit copy-back instructions should be inserted right before the terminator. Before this fix, they were wrongly placed at the beginning of the basic block. I will commit fixes to other platforms as well. PR26136 llvm-svn: 257925
This commit is contained in:
		
							parent
							
								
									285d7bd4e7
								
							
						
					
					
						commit
						4fe01bd8f9
					
				| 
						 | 
					@ -28908,6 +28908,7 @@ void X86TargetLowering::insertCopiesSplitCSR(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const TargetInstrInfo *TII = Subtarget->getInstrInfo();
 | 
					  const TargetInstrInfo *TII = Subtarget->getInstrInfo();
 | 
				
			||||||
  MachineRegisterInfo *MRI = &Entry->getParent()->getRegInfo();
 | 
					  MachineRegisterInfo *MRI = &Entry->getParent()->getRegInfo();
 | 
				
			||||||
 | 
					  MachineBasicBlock::iterator MBBI = Entry->begin();
 | 
				
			||||||
  for (const MCPhysReg *I = IStart; *I; ++I) {
 | 
					  for (const MCPhysReg *I = IStart; *I; ++I) {
 | 
				
			||||||
    const TargetRegisterClass *RC = nullptr;
 | 
					    const TargetRegisterClass *RC = nullptr;
 | 
				
			||||||
    if (X86::GR64RegClass.contains(*I))
 | 
					    if (X86::GR64RegClass.contains(*I))
 | 
				
			||||||
| 
						 | 
					@ -28925,13 +28926,13 @@ void X86TargetLowering::insertCopiesSplitCSR(
 | 
				
			||||||
               Attribute::NoUnwind) &&
 | 
					               Attribute::NoUnwind) &&
 | 
				
			||||||
           "Function should be nounwind in insertCopiesSplitCSR!");
 | 
					           "Function should be nounwind in insertCopiesSplitCSR!");
 | 
				
			||||||
    Entry->addLiveIn(*I);
 | 
					    Entry->addLiveIn(*I);
 | 
				
			||||||
    BuildMI(*Entry, Entry->begin(), DebugLoc(), TII->get(TargetOpcode::COPY),
 | 
					    BuildMI(*Entry, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY), NewVR)
 | 
				
			||||||
            NewVR)
 | 
					 | 
				
			||||||
        .addReg(*I);
 | 
					        .addReg(*I);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Insert the copy-back instructions right before the terminator.
 | 
				
			||||||
    for (auto *Exit : Exits)
 | 
					    for (auto *Exit : Exits)
 | 
				
			||||||
      BuildMI(*Exit, Exit->begin(), DebugLoc(), TII->get(TargetOpcode::COPY),
 | 
					      BuildMI(*Exit, Exit->getFirstTerminator(), DebugLoc(),
 | 
				
			||||||
              *I)
 | 
					              TII->get(TargetOpcode::COPY), *I)
 | 
				
			||||||
          .addReg(NewVR);
 | 
					          .addReg(NewVR);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,6 +9,7 @@
 | 
				
			||||||
@sg = internal thread_local global %struct.S zeroinitializer, align 1
 | 
					@sg = internal thread_local global %struct.S zeroinitializer, align 1
 | 
				
			||||||
@__dso_handle = external global i8
 | 
					@__dso_handle = external global i8
 | 
				
			||||||
@__tls_guard = internal thread_local unnamed_addr global i1 false
 | 
					@__tls_guard = internal thread_local unnamed_addr global i1 false
 | 
				
			||||||
 | 
					@sum1 = internal thread_local global i32 0, align 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
declare void @_ZN1SC1Ev(%struct.S*)
 | 
					declare void @_ZN1SC1Ev(%struct.S*)
 | 
				
			||||||
declare void @_ZN1SD1Ev(%struct.S*)
 | 
					declare void @_ZN1SD1Ev(%struct.S*)
 | 
				
			||||||
| 
						 | 
					@ -50,3 +51,17 @@ init.i:
 | 
				
			||||||
__tls_init.exit:
 | 
					__tls_init.exit:
 | 
				
			||||||
  ret %struct.S* @sg
 | 
					  ret %struct.S* @sg
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; CHECK-LABEL: _ZTW4sum1
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %r11
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %r10
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %r9
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %r8
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %rsi
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %rdx
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %rcx
 | 
				
			||||||
 | 
					; CHECK-NOT: pushq %rbx
 | 
				
			||||||
 | 
					; CHECK: callq
 | 
				
			||||||
 | 
					define cxx_fast_tlscc nonnull i32* @_ZTW4sum1() nounwind {
 | 
				
			||||||
 | 
					  ret i32* @sum1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue