From: Matthias Braun Date: Mon, 22 Oct 2018 22:52:23 +0000 (+0000) Subject: X86: Do not optimize branches with undef eflags inputs X-Git-Tag: llvmorg-8.0.0-rc1~6096 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0beeffeed3d24cf65ec165141926f7715380eb2;p=platform%2Fupstream%2Fllvm.git X86: Do not optimize branches with undef eflags inputs analyzeBranch()/insertBranch() etc. do not properly deal with an undef flag on the eflags input and used to produce invalid MIR. I don't see this ever affecting real world inputs (I don't think it is possible to produce undef flags with llvm IR), so I simply changed the code to bail out in this case. rdar://42122367 llvm-svn: 344970 --- diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp index 36ef7dc..1eddb27 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -2640,6 +2640,11 @@ bool X86InstrInfo::AnalyzeBranchImpl( if (BranchCode == X86::COND_INVALID) return true; // Can't handle indirect branch. + // In practice we should never have an undef eflags operand, if we do + // abort here as we are not prepared to preserve the flag. + if (I->getOperand(1).isUndef()) + return true; + // Working from the bottom, handle the first conditional branch. if (Cond.empty()) { MachineBasicBlock *TargetBB = I->getOperand(0).getMBB(); diff --git a/llvm/test/CodeGen/X86/undef-eflags.mir b/llvm/test/CodeGen/X86/undef-eflags.mir new file mode 100644 index 0000000..e5cf58b --- /dev/null +++ b/llvm/test/CodeGen/X86/undef-eflags.mir @@ -0,0 +1,18 @@ +# RUN: llc -o - %s -mtriple=x86_64-- -verify-machineinstrs -run-pass branch-folder | FileCheck %s +# Check that we do not generate invalid MIR when optimizing condjumps with undef +# flags on the eflags input (currently we should just bail out). +--- +# CHECK-LABEL: name: fallundef +name: fallundef +tracksRegLiveness: true +body: | + bb.0: + JE_1 %bb.1, implicit undef $eflags + ; CHECK: JE_1 %bb.1, implicit undef $eflags + JMP_1 %bb.2 + bb.1: + RET 2, undef $eax + + bb.2: + RET 0, undef $eax +...