Index: lib/Target/X86/X86VZeroUpper.cpp =================================================================== --- lib/Target/X86/X86VZeroUpper.cpp +++ lib/Target/X86/X86VZeroUpper.cpp @@ -128,6 +128,11 @@ } static bool hasYmmReg(MachineInstr *MI) { + // For the purpose of inserting VZERO* instructions, ignore existing VZERO* + // instructions. + if (MI->getOpcode() == X86::VZEROALL || MI->getOpcode() == X86::VZEROUPPER) + return false; + for (const MachineOperand &MO : MI->operands()) { if (MI->isCall() && MO.isRegMask() && !clobbersAllYmmRegs(MO)) return true; Index: test/CodeGen/X86/avx-intrinsics-x86.ll =================================================================== --- test/CodeGen/X86/avx-intrinsics-x86.ll +++ test/CodeGen/X86/avx-intrinsics-x86.ll @@ -4755,7 +4755,6 @@ ; AVX-LABEL: test_x86_avx_vzeroall: ; AVX: ## BB#0: ; AVX-NEXT: vzeroall -; AVX-NEXT: vzeroupper ; AVX-NEXT: retl ; ; AVX512VL-LABEL: test_x86_avx_vzeroall: @@ -4772,7 +4771,6 @@ ; AVX-LABEL: test_x86_avx_vzeroupper: ; AVX: ## BB#0: ; AVX-NEXT: vzeroupper -; AVX-NEXT: vzeroupper ; AVX-NEXT: retl ; ; AVX512VL-LABEL: test_x86_avx_vzeroupper: