From: Matthias Braun Date: Sat, 4 Feb 2017 02:27:13 +0000 (+0000) Subject: MachineCopyPropagation: Do not consider undef operands as clobbers X-Git-Tag: android-x86-7.1-r4~20880 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e92225895ce25075708eb60a0ad50ea3078d8318;p=android-x86%2Fexternal-llvm.git MachineCopyPropagation: Do not consider undef operands as clobbers This was originally introduced in r278321 to work around correctness problems in the ExecutionDepsFix pass; Probably also to keep the performance benefits of breaking the false dependencies which of course also affect undef operands. ExecutionDepsFix has been improved here recently (see for example r278321) so we should not need this exception any longer. Differential Revision: https://reviews.llvm.org/D29525 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294087 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/MachineCopyPropagation.cpp b/lib/CodeGen/MachineCopyPropagation.cpp index 92d043df26b..8662a30a084 100644 --- a/lib/CodeGen/MachineCopyPropagation.cpp +++ b/lib/CodeGen/MachineCopyPropagation.cpp @@ -280,14 +280,6 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { MaybeDeadCopies.remove(CI->second); } } - // Treat undef use like defs for copy propagation but not for - // dead copy. We would need to do a liveness check to be sure the copy - // is dead for undef uses. - // The backends are allowed to do whatever they want with undef value - // and we cannot be sure this register will not be rewritten to break - // some false dependencies for the hardware for instance. - if (MO.isUndef()) - Defs.push_back(Reg); } // The instruction has a register mask operand which means that it clobbers diff --git a/test/CodeGen/X86/copy-propagation.ll b/test/CodeGen/X86/copy-propagation.ll index dac46c17382..4d8b8462b5f 100644 --- a/test/CodeGen/X86/copy-propagation.ll +++ b/test/CodeGen/X86/copy-propagation.ll @@ -1,38 +1,25 @@ ; RUN: llc %s -mattr=+avx -o - | FileCheck %s -; PR21743. +; Originally from http://llvm.org/PR21743. target triple = "x86_64-pc-win32-elf" -; Check that copy propagation conservatively assumes that undef register -; can be rewritten by the backend to break false dependencies for the -; hardware. -; In this function we are in this situation: -; reg1 = copy reg2 -; = inst reg2 -; reg2 = copy reg1 -; Copy propagation used to remove the last copy. -; This is incorrect because the undef flag on reg2 in inst, allows next -; passes to put whatever trashed value in reg2 that may help. -; In practice we end up with this code: -; reg1 = copy reg2 -; reg2 = 0 -; = inst reg2 -; reg2 = copy reg1 -; Therefore, removing the last copy is wrong. +; Copy propagation may remove COPYs if the result is only used by undef +; operands. ; ; CHECK-LABEL: foo: ; CHECK: movl $339752784, %e[[INDIRECT_CALL1:[a-z]+]] ; CHECK: callq *%r[[INDIRECT_CALL1]] ; Copy the result in a temporary. -; Note: Technically the regalloc could have been smarter and this move not required, -; which would have hidden the bug. +; Note: Technically the regalloc could have been smarter and this move not +; required, which would have hidden the bug. ; CHECK: vmovapd %xmm0, [[TMP:%xmm[0-9]+]] -; Crush xmm0. -; CHECK-NEXT: vxorps %xmm0, %xmm0, %xmm0 +; CHECK-NOT: vxorps %xmm0, %xmm0, %xmm0 +; CHECK-NEXT: vcvtsi2sdq %rsi, %xmm0, %xmm6 ; CHECK: movl $339772768, %e[[INDIRECT_CALL2:[a-z]+]] +; CHECK-NOT: vmovapd %xmm7, %xmm0 +; CHECK-NEXT: vmovapd %xmm6, %xmm1 ; Set TMP in the first argument of the second call. -; CHECK-NEXT: vmovapd [[TMP]], %xmm0 -; CHECK: callq *%r[[INDIRECT_CALL2]] +; CHECK_NEXT: callq *%r[[INDIRECT_CALL2]] ; CHECK: retq define double @foo(i64 %arg) { top: