Index: src/IceTargetLoweringMIPS32.cpp |
diff --git a/src/IceTargetLoweringMIPS32.cpp b/src/IceTargetLoweringMIPS32.cpp |
index 66d17f87bb72969244b628d5cf9a293e11ca47e4..77fc5405d8b811d6f32c72b62208bba64717020c 100644 |
--- a/src/IceTargetLoweringMIPS32.cpp |
+++ b/src/IceTargetLoweringMIPS32.cpp |
@@ -2553,30 +2553,72 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) { |
Variable *T = makeReg(Dest->getType()); |
Variable *Src0R = legalizeToReg(Src0); |
- Variable *Src1R = legalizeToReg(Src1); |
+ Variable *Src1R = nullptr; |
+ uint32_t Value = 0; |
+ auto *Const32 = llvm::dyn_cast<ConstantInteger32>(Src1); |
Jim Stichnoth
2016/11/04 13:18:48
Can you move the definition of Const32 into the sw
jaydeep.patil
2016/11/07 03:55:11
Done.
|
+ |
+ switch (Instr->getOp()) { |
+ case InstArithmetic::Add: |
+ case InstArithmetic::And: |
+ case InstArithmetic::Or: |
+ case InstArithmetic::Xor: |
+ case InstArithmetic::Sub: |
+ case InstArithmetic::Shl: |
+ case InstArithmetic::Lshr: |
+ case InstArithmetic::Ashr: |
+ if (Const32 != nullptr && isInt<16>(int32_t(Const32->getValue()))) { |
+ Value = Const32->getValue(); |
+ } else { |
+ Src1R = legalizeToReg(Src1); |
+ } |
+ break; |
+ default: |
+ Src1R = legalizeToReg(Src1); |
+ break; |
+ } |
constexpr uint32_t DivideByZeroTrapCode = 7; |
switch (Instr->getOp()) { |
case InstArithmetic::_num: |
break; |
case InstArithmetic::Add: |
- _addu(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
Jim Stichnoth
2016/11/04 13:18:47
Instead of the "(Src1R == nullptr)" idiom, I think
jaydeep.patil
2016/11/07 03:55:11
Done.
|
+ _addiu(T, Src0R, Value); |
+ } else { |
+ _addu(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
case InstArithmetic::And: |
- _and(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
+ _andi(T, Src0R, Value); |
+ } else { |
+ _and(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
case InstArithmetic::Or: |
- _or(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
+ _ori(T, Src0R, Value); |
+ } else { |
+ _or(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
case InstArithmetic::Xor: |
- _xor(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
+ _xori(T, Src0R, Value); |
+ } else { |
+ _xor(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
case InstArithmetic::Sub: |
- _subu(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
+ _addiu(T, Src0R, -Value); |
+ } else { |
+ _subu(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
case InstArithmetic::Mul: { |
@@ -2585,7 +2627,11 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) { |
return; |
} |
case InstArithmetic::Shl: { |
- _sllv(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
+ _sll(T, Src0R, Value); |
+ } else { |
+ _sllv(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
} |
@@ -2595,15 +2641,25 @@ void TargetMIPS32::lowerArithmetic(const InstArithmetic *Instr) { |
if (Dest->getType() != IceType_i32) { |
T0R = makeReg(IceType_i32); |
lowerCast(InstCast::create(Func, InstCast::Zext, T0R, Src0R)); |
- T1R = makeReg(IceType_i32); |
- lowerCast(InstCast::create(Func, InstCast::Zext, T1R, Src1R)); |
+ if (Src1R != nullptr) { |
+ T1R = makeReg(IceType_i32); |
+ lowerCast(InstCast::create(Func, InstCast::Zext, T1R, Src1R)); |
+ } |
+ } |
+ if (Src1R == nullptr) { |
+ _srl(T, T0R, Value); |
+ } else { |
+ _srlv(T, T0R, T1R); |
} |
- _srlv(T, T0R, T1R); |
_mov(Dest, T); |
return; |
} |
case InstArithmetic::Ashr: { |
- _srav(T, Src0R, Src1R); |
+ if (Src1R == nullptr) { |
+ _sra(T, Src0R, Value); |
+ } else { |
+ _srav(T, Src0R, Src1R); |
+ } |
_mov(Dest, T); |
return; |
} |