Commit 90db6ae0 by Jim Stichnoth

Subzero: Simplify the icmp i64 lowering.

The original code for 64-bit icmp lowering had separate cases for eq/ne versus other conditions, mostly because eq/ne need two 32-bit comparisons while the others need three. However, with small changes, we can handle everything uniformly, simplifying the code. This gets thoroughly tested by the test_icmp cross test. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4162 R=jvoung@chromium.org Review URL: https://codereview.chromium.org/1130023002
parent f48b320c
......@@ -2710,8 +2710,6 @@ void TargetX8632::lowerIcmp(const InstIcmp *Inst) {
}
// a=icmp cond, b, c ==> cmp b,c; a=1; br cond,L1; FakeUse(a); a=0; L1:
Constant *Zero = Ctx->getConstantZero(IceType_i32);
Constant *One = Ctx->getConstantInt32(1);
if (Src0->getType() == IceType_i64) {
InstIcmp::ICond Condition = Inst->getCondition();
size_t Index = static_cast<size_t>(Condition);
......@@ -2720,28 +2718,21 @@ void TargetX8632::lowerIcmp(const InstIcmp *Inst) {
Operand *Src0HiRM = legalize(hiOperand(Src0), Legal_Reg | Legal_Mem);
Operand *Src1LoRI = legalize(loOperand(Src1), Legal_Reg | Legal_Imm);
Operand *Src1HiRI = legalize(hiOperand(Src1), Legal_Reg | Legal_Imm);
if (Condition == InstIcmp::Eq || Condition == InstIcmp::Ne) {
InstX8632Label *Label = InstX8632Label::create(Func, this);
_mov(Dest, (Condition == InstIcmp::Eq ? Zero : One));
_cmp(Src0LoRM, Src1LoRI);
_br(CondX86::Br_ne, Label);
_cmp(Src0HiRM, Src1HiRI);
_br(CondX86::Br_ne, Label);
_mov_nonkillable(Dest, (Condition == InstIcmp::Eq ? One : Zero));
Context.insert(Label);
} else {
InstX8632Label *LabelFalse = InstX8632Label::create(Func, this);
InstX8632Label *LabelTrue = InstX8632Label::create(Func, this);
_mov(Dest, One);
_cmp(Src0HiRM, Src1HiRI);
Constant *Zero = Ctx->getConstantZero(IceType_i32);
Constant *One = Ctx->getConstantInt32(1);
InstX8632Label *LabelFalse = InstX8632Label::create(Func, this);
InstX8632Label *LabelTrue = InstX8632Label::create(Func, this);
_mov(Dest, One);
_cmp(Src0HiRM, Src1HiRI);
if (TableIcmp64[Index].C1 != CondX86::Br_None)
_br(TableIcmp64[Index].C1, LabelTrue);
if (TableIcmp64[Index].C2 != CondX86::Br_None)
_br(TableIcmp64[Index].C2, LabelFalse);
_cmp(Src0LoRM, Src1LoRI);
_br(TableIcmp64[Index].C3, LabelTrue);
Context.insert(LabelFalse);
_mov_nonkillable(Dest, Zero);
Context.insert(LabelTrue);
}
_cmp(Src0LoRM, Src1LoRI);
_br(TableIcmp64[Index].C3, LabelTrue);
Context.insert(LabelFalse);
_mov_nonkillable(Dest, Zero);
Context.insert(LabelTrue);
return;
}
......
......@@ -38,8 +38,8 @@
#define ICMPX8632_TABLE \
/* val, C_32, C1_64, C2_64, C3_64 */ \
X(Eq, Br_e, Br_None, Br_None, Br_None) \
X(Ne, Br_ne, Br_None, Br_None, Br_None) \
X(Eq, Br_e, Br_None, Br_ne, Br_e) \
X(Ne, Br_ne, Br_ne, Br_None, Br_ne) \
X(Ugt, Br_a, Br_a, Br_b, Br_a) \
X(Uge, Br_ae, Br_a, Br_b, Br_ae) \
X(Ult, Br_b, Br_b, Br_a, Br_b) \
......
......@@ -732,18 +732,18 @@ if.end3: ; preds = %if.then2, %if.end
}
; CHECK-LABEL: icmpEq64
; CHECK: jne
; CHECK: jne
; CHECK: je
; CHECK: call
; CHECK: jne
; CHECK: jne
; CHECK: je
; CHECK: call
;
; OPTM1-LABEL: icmpEq64
; OPTM1: jne
; OPTM1: jne
; OPTM1: je
; OPTM1: call
; OPTM1: jne
; OPTM1: jne
; OPTM1: je
; OPTM1: call
declare void @func()
......@@ -952,11 +952,11 @@ entry:
}
; CHECK-LABEL: icmpEq64Bool
; CHECK: jne
; CHECK: jne
; CHECK: je
;
; OPTM1-LABEL: icmpEq64Bool
; OPTM1: jne
; OPTM1: jne
; OPTM1: je
define internal i32 @icmpNe64Bool(i64 %a, i64 %b) {
entry:
......
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