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
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();
--- /dev/null
+# 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
+...