Commit c070d6f7 by Karl Schimpf

Fixes bug on conditional branch where the targets are the same.

Fixes constructor InstBr when it is a conditional branch, and the true and false branches are the same. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4212 R=jpp@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/1215443002.
parent 7cd5351c
...@@ -270,10 +270,10 @@ InstAssign::InstAssign(Cfg *Func, Variable *Dest, Operand *Source) ...@@ -270,10 +270,10 @@ InstAssign::InstAssign(Cfg *Func, Variable *Dest, Operand *Source)
// If TargetTrue==TargetFalse, we turn it into an unconditional // If TargetTrue==TargetFalse, we turn it into an unconditional
// branch. This ensures that, along with the 'switch' instruction // branch. This ensures that, along with the 'switch' instruction
// semantics, there is at most one edge from one node to another. // semantics, there is at most one edge from one node to another.
InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue, InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue_,
CfgNode *TargetFalse) CfgNode *TargetFalse_)
: InstHighLevel(Func, Inst::Br, 1, nullptr), TargetFalse(TargetFalse), : InstHighLevel(Func, Inst::Br, 1, nullptr), TargetFalse(TargetFalse_),
TargetTrue(TargetTrue) { TargetTrue(TargetTrue_) {
if (TargetTrue == TargetFalse) { if (TargetTrue == TargetFalse) {
TargetTrue = nullptr; // turn into unconditional version TargetTrue = nullptr; // turn into unconditional version
} else { } else {
......
; Test conditional branch where targets are the same.
; Tests issue: https://code.google.com/p/nativeclient/issues/detail?id=4212
; RUN: %p2i -i %s --insts | FileCheck %s
define void @f(i32 %foo, i32 %bar) {
entry:
%c = icmp ult i32 %foo, %bar
br i1 %c, label %block, label %block
block:
ret void
}
; Note that the branch is converted to an unconditional branch.
; CHECK: define void @f(i32 %foo, i32 %bar) {
; CHECK-NEXT: entry:
; CHECK-NEXT: %c = icmp ult i32 %foo, %bar
; CHECK-NEXT: br label %block
; CHECK-NEXT: block:
; CHECK-NEXT: ret void
; CHECK-NEXT: }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment