Index: lib/Target/X86/X86InstrInfo.cpp =================================================================== --- lib/Target/X86/X86InstrInfo.cpp +++ lib/Target/X86/X86InstrInfo.cpp @@ -926,6 +926,14 @@ const MachineOperand &Dest = MI.getOperand(0); const MachineOperand &Src = MI.getOperand(1); + // Ideally, operations with undef should be folded before we get here, but we + // can't guarantee it. Bail out because optimizing undefs is a waste of time. + if (Src.isUndef()) + return nullptr; + if (MI.getNumOperands() > 2) + if (MI.getOperand(2).isReg() && MI.getOperand(2).isUndef()) + return nullptr; + MachineInstr *NewMI = nullptr; // FIXME: 16-bit LEA's are really slow on Athlons, but not bad on P4's. When // we have better subtarget support, enable the 16-bit LEA generation here. Index: test/CodeGen/X86/GlobalISel/undef.ll =================================================================== --- test/CodeGen/X86/GlobalISel/undef.ll +++ test/CodeGen/X86/GlobalISel/undef.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py -; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=ALL +; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=ALL define i8 @test() { ; ALL-LABEL: test: @@ -8,8 +8,8 @@ ret i8 undef } -define i8 @test2(i8 %a) { -; ALL-LABEL: test2: +define i8 @add_undef_i8(i8 %a) { +; ALL-LABEL: add_undef_i8: ; ALL: # %bb.0: ; ALL-NEXT: movl %edi, %eax ; ALL-NEXT: addb %al, %al @@ -19,6 +19,26 @@ ret i8 %r } +define i16 @add_undef_i16(i16 %a) { +; ALL-LABEL: add_undef_i16: +; ALL: # %bb.0: +; ALL-NEXT: movl %edi, %eax +; ALL-NEXT: addw %ax, %ax +; ALL-NEXT: # kill: def $ax killed $ax killed $eax +; ALL-NEXT: retq + %r = add i16 %a, undef + ret i16 %r +} + +define i32 @add_undef_i32(i32 %a) { +; ALL-LABEL: add_undef_i32: +; ALL: # %bb.0: +; ALL-NEXT: movl %edi, %eax +; ALL-NEXT: addl %eax, %eax +; ALL-NEXT: retq + %r = add i32 %a, undef + ret i32 %r +} define float @test3() { ; ALL-LABEL: test3: