summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2018-10-22 22:52:23 +0000
committerMatthias Braun <matze@braunis.de>2018-10-22 22:52:23 +0000
commita0beeffeed3d24cf65ec165141926f7715380eb2 (patch)
tree1e3ed39a0ac18d14c15cbef9e3a18b877f03a57d
parent767625400d2dafce663dfad420d4ad8d03426584 (diff)
downloadbcm5719-llvm-a0beeffeed3d24cf65ec165141926f7715380eb2.tar.gz
bcm5719-llvm-a0beeffeed3d24cf65ec165141926f7715380eb2.zip
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
-rw-r--r--llvm/lib/Target/X86/X86InstrInfo.cpp5
-rw-r--r--llvm/test/CodeGen/X86/undef-eflags.mir18
2 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index 36ef7dca1f3..1eddb27847d 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 00000000000..e5cf58bac68
--- /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
+...
OpenPOWER on IntegriCloud