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

Unified Diff: src/IceTargetLoweringX8632.cpp

Issue 459133002: Subzero: address mode opt: Transform *(reg+const) into [reg+const]. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Whitespace, comments, logic Created 6 years, 4 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/IceTargetLoweringX8632.cpp
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index 26d11b9208d84dde23ce57816bb0986be1c6a69d..47684932737e6154f463f5c6d9b50efe600a793c 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -3398,14 +3398,32 @@ void computeAddressOpt(Variable *&Base, Variable *&Index, uint16_t &Shift,
// swap(Index,Base)
// Similar for Base=Const*Var and Base=Var<<Const
- // Base is Base=Var+Const ==>
+ // Base is Base=Var+Const || Base is Base=Const+Var ==>
// set Base=Var, Offset+=Const
-
- // Base is Base=Const+Var ==>
- // set Base=Var, Offset+=Const
-
// Base is Base=Var-Const ==>
// set Base=Var, Offset-=Const
+ const InstArithmetic *ArithInst =
+ llvm::dyn_cast_or_null<const InstArithmetic>(BaseInst);
+ if (ArithInst && (ArithInst->getOp() == InstArithmetic::Add ||
+ ArithInst->getOp() == InstArithmetic::Sub)) {
+ bool IsAdd = ArithInst->getOp() == InstArithmetic::Add;
+ Variable *Var = NULL;
+ ConstantInteger *Const = NULL;
+ if (Variable *VariableOperand =
+ llvm::dyn_cast<Variable>(ArithInst->getSrc(0))) {
+ Var = VariableOperand;
+ Const = llvm::dyn_cast<ConstantInteger>(ArithInst->getSrc(1));
+ } else if (IsAdd) {
+ Const = llvm::dyn_cast<ConstantInteger>(ArithInst->getSrc(0));
+ Var = llvm::dyn_cast<Variable>(ArithInst->getSrc(1));
+ }
+ if (!(Const && Var)) {
+ break;
+ }
+ Base = Var;
+ Offset += IsAdd ? Const->getValue() : -Const->getValue();
+ continue;
+ }
// Index is Index=Var+Const ==>
// set Index=Var, Offset+=(Const<<Shift)
@@ -4039,7 +4057,7 @@ void TargetX8632::postLower() {
template <> void ConstantInteger::emit(GlobalContext *Ctx) const {
Ostream &Str = Ctx->getStrEmit();
- Str << getValue();
+ Str << (int64_t) getValue();
}
template <> void ConstantFloat::emit(GlobalContext *Ctx) const {
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/address-mode-opt.ll » ('j') | tests_lit/llvm2ice_tests/address-mode-opt.ll » ('J')

Powered by Google App Engine
This is Rietveld 408576698