Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: src/IceTargetLoweringMIPS32.cpp

Issue 2339323004: [SubZero] Use DIV instruction instead of TargetHelperCall (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Alphabetize Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceTargetLoweringMIPS32.cpp
diff --git a/src/IceTargetLoweringMIPS32.cpp b/src/IceTargetLoweringMIPS32.cpp
index c4b602463f20af75a03df68d14f4f43a92998fa5..b3570a63c5c2a1f78158195e121c09e3d2842afd 100644
--- a/src/IceTargetLoweringMIPS32.cpp
+++ b/src/IceTargetLoweringMIPS32.cpp
@@ -277,71 +277,6 @@ void TargetMIPS32::genTargetHelperCallFor(Inst *Instr) {
Instr->setDeleted();
return;
}
- case IceType_i32:
- case IceType_i16:
- case IceType_i8: {
- InstCast::OpKind CastKind;
- RuntimeHelper HelperID = RuntimeHelper::H_Num;
- switch (Op) {
- default:
- return;
- case InstArithmetic::Udiv:
- HelperID = RuntimeHelper::H_udiv_i32;
- CastKind = InstCast::Zext;
- break;
- case InstArithmetic::Sdiv:
- HelperID = RuntimeHelper::H_sdiv_i32;
- CastKind = InstCast::Sext;
- break;
- case InstArithmetic::Urem:
- HelperID = RuntimeHelper::H_urem_i32;
- CastKind = InstCast::Zext;
- break;
- case InstArithmetic::Srem:
- HelperID = RuntimeHelper::H_srem_i32;
- CastKind = InstCast::Sext;
- break;
- }
-
- if (HelperID == RuntimeHelper::H_Num) {
- return;
- }
-
- Operand *Src0 = Instr->getSrc(0);
- Operand *Src1 = Instr->getSrc(1);
- if (DestTy != IceType_i32) {
- // Src0 and Src1 have to be zero-, or signed-extended to i32. For Src0,
- // we just insert a InstCast right before the call to the helper.
- Variable *Src0_32 = Func->makeVariable(IceType_i32);
- Context.insert<InstCast>(CastKind, Src0_32, Src0);
- Src0 = Src0_32;
-
- if (auto *C = llvm::dyn_cast<ConstantInteger32>(Src1)) {
- const int32_t ShAmt = (DestTy == IceType_i16) ? 16 : 24;
- int32_t NewC = C->getValue();
- if (CastKind == InstCast::Zext) {
- NewC &= ~(0x80000000l >> ShAmt);
- } else {
- NewC = (NewC << ShAmt) >> ShAmt;
- }
- Src1 = Ctx->getConstantInt32(NewC);
- } else {
- Variable *Src1_32 = Func->makeVariable(IceType_i32);
- Context.insert<InstCast>(CastKind, Src1_32, Src1);
- Src1 = Src1_32;
- }
- }
- Operand *TargetHelper = Ctx->getRuntimeHelperFunc(HelperID);
- constexpr SizeT MaxArgs = 2;
- auto *Call = Context.insert<InstCall>(MaxArgs, Dest, TargetHelper,
- NoTailCall, IsTargetHelperCall);
- assert(Src0->getType() == IceType_i32);
- Call->addArg(Src0);
- assert(Src1->getType() == IceType_i32);
- Call->addArg(Src1);
- Instr->setDeleted();
- return;
- }
case IceType_f32:
case IceType_f64: {
if (Op != InstArithmetic::Frem) {
@@ -1957,6 +1892,7 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) {
case InstArithmetic::Udiv: {
auto *T_Zero = I32Reg(RegMIPS32::Reg_ZERO);
_divu(T_Zero, Src0R, Src1R);
+ _teq(Src1R, T_Zero, 7); // Trap if divide-by-zero
Jim Stichnoth 2016/09/16 16:33:02 I like to avoid magic constants when possible. In
jaydeep.patil 2016/09/19 03:30:51 Done.
_mflo(T, T_Zero);
_mov(Dest, T);
return;
@@ -1964,6 +1900,7 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) {
case InstArithmetic::Sdiv: {
auto *T_Zero = I32Reg(RegMIPS32::Reg_ZERO);
_div(T_Zero, Src0R, Src1R);
+ _teq(Src1R, T_Zero, 7); // Trap if divide-by-zero
obucinac 2016/09/19 03:37:04 auto *T_Zero = I32Reg(RegMIPS32::Reg_ZERO); _teq(S
jaydeep.patil 2016/09/19 05:04:40 Calling getZero() for each occurrence of T_Zero is
_mflo(T, T_Zero);
_mov(Dest, T);
return;
@@ -1971,6 +1908,7 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) {
case InstArithmetic::Urem: {
auto *T_Zero = I32Reg(RegMIPS32::Reg_ZERO);
_divu(T_Zero, Src0R, Src1R);
+ _teq(Src1R, T_Zero, 7); // Trap if divide-by-zero
_mfhi(T, T_Zero);
_mov(Dest, T);
return;
@@ -1978,6 +1916,7 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) {
case InstArithmetic::Srem: {
auto *T_Zero = I32Reg(RegMIPS32::Reg_ZERO);
_div(T_Zero, Src0R, Src1R);
+ _teq(Src1R, T_Zero, 7); // Trap if divide-by-zero
_mfhi(T, T_Zero);
_mov(Dest, T);
return;

Powered by Google App Engine
This is Rietveld 408576698