Skip to content

Commit cdcce2d

Browse files
author
Dan Gohman
committed
[WebAssembly] Update the br_if instructions' operand orders to match the spec.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260152 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6ac56c2 commit cdcce2d

File tree

5 files changed

+119
-119
lines changed

5 files changed

+119
-119
lines changed

lib/Target/WebAssembly/WebAssemblyInstrControl.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ let Defs = [ARGUMENTS] in {
1616

1717
let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
1818
// The condition operand is a boolean value which WebAssembly represents as i32.
19-
def BR_IF : I<(outs), (ins I32:$cond, bb_op:$dst),
19+
def BR_IF : I<(outs), (ins bb_op:$dst, I32:$cond),
2020
[(brcond I32:$cond, bb:$dst)],
21-
"br_if \t$cond, $dst">;
21+
"br_if \t$dst, $cond">;
2222
let isCodeGenOnly = 1 in
23-
def BR_UNLESS : I<(outs), (ins I32:$cond, bb_op:$dst), [],
24-
"br_unless\t$cond, $dst">;
23+
def BR_UNLESS : I<(outs), (ins bb_op:$dst, I32:$cond), [],
24+
"br_unless\t$dst, $cond">;
2525
let isBarrier = 1 in {
2626
def BR : I<(outs), (ins bb_op:$dst),
2727
[(br bb:$dst)],
@@ -32,9 +32,9 @@ def BR : I<(outs), (ins bb_op:$dst),
3232
} // Defs = [ARGUMENTS]
3333

3434
def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst),
35-
(BR_IF I32:$cond, bb_op:$dst)>;
35+
(BR_IF bb_op:$dst, I32:$cond)>;
3636
def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
37-
(BR_UNLESS I32:$cond, bb_op:$dst)>;
37+
(BR_UNLESS bb_op:$dst, I32:$cond)>;
3838

3939
let Defs = [ARGUMENTS] in {
4040

lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,22 @@ bool WebAssemblyInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
107107
if (HaveCond)
108108
return true;
109109
// If we're running after CFGStackify, we can't optimize further.
110-
if (!MI.getOperand(1).isMBB())
110+
if (!MI.getOperand(0).isMBB())
111111
return true;
112112
Cond.push_back(MachineOperand::CreateImm(true));
113-
Cond.push_back(MI.getOperand(0));
114-
TBB = MI.getOperand(1).getMBB();
113+
Cond.push_back(MI.getOperand(1));
114+
TBB = MI.getOperand(0).getMBB();
115115
HaveCond = true;
116116
break;
117117
case WebAssembly::BR_UNLESS:
118118
if (HaveCond)
119119
return true;
120120
// If we're running after CFGStackify, we can't optimize further.
121-
if (!MI.getOperand(1).isMBB())
121+
if (!MI.getOperand(0).isMBB())
122122
return true;
123123
Cond.push_back(MachineOperand::CreateImm(false));
124-
Cond.push_back(MI.getOperand(0));
125-
TBB = MI.getOperand(1).getMBB();
124+
Cond.push_back(MI.getOperand(1));
125+
TBB = MI.getOperand(0).getMBB();
126126
HaveCond = true;
127127
break;
128128
case WebAssembly::BR:
@@ -177,11 +177,11 @@ unsigned WebAssemblyInstrInfo::InsertBranch(MachineBasicBlock &MBB,
177177
assert(Cond.size() == 2 && "Expected a flag and a successor block");
178178

179179
if (Cond[0].getImm()) {
180-
BuildMI(&MBB, DL, get(WebAssembly::BR_IF)).addOperand(Cond[1]).addMBB(TBB);
180+
BuildMI(&MBB, DL, get(WebAssembly::BR_IF)).addMBB(TBB).addOperand(Cond[1]);
181181
} else {
182182
BuildMI(&MBB, DL, get(WebAssembly::BR_UNLESS))
183-
.addOperand(Cond[1])
184-
.addMBB(TBB);
183+
.addMBB(TBB)
184+
.addOperand(Cond[1]);
185185
}
186186
if (!FBB)
187187
return 1;

lib/Target/WebAssembly/WebAssemblyLowerBrUnless.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool WebAssemblyLowerBrUnless::runOnMachineFunction(MachineFunction &MF) {
6666
if (MI->getOpcode() != WebAssembly::BR_UNLESS)
6767
continue;
6868

69-
unsigned Cond = MI->getOperand(0).getReg();
69+
unsigned Cond = MI->getOperand(1).getReg();
7070
bool Inverted = false;
7171

7272
// Attempt to invert the condition in place.
@@ -124,8 +124,8 @@ bool WebAssemblyLowerBrUnless::runOnMachineFunction(MachineFunction &MF) {
124124
// delete the br_unless.
125125
assert(Inverted);
126126
BuildMI(MBB, MI, MI->getDebugLoc(), TII.get(WebAssembly::BR_IF))
127-
.addReg(Cond)
128-
.addOperand(MI->getOperand(1));
127+
.addOperand(MI->getOperand(0))
128+
.addReg(Cond);
129129
MBB.erase(MI);
130130
}
131131
}

0 commit comments

Comments
 (0)