Subzero: address mode opt: Transform *(reg+const) into [reg+const].

Teach address mode optimization about Base=Base+Const,
Base=Const+Base, and Base=Base-Const patterns.

Change ConstantInteger::emit() to emit signed values.

BUG=none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/459133002
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index 26d11b9..de033a5 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -3388,6 +3388,33 @@
       }
     }
 
+    // Base is Base=Var+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 && Const+Shift<=3 ==>
     //   Index=Var, Shift+=Const
 
@@ -3398,15 +3425,6 @@
     //   swap(Index,Base)
     // Similar for Base=Const*Var and Base=Var<<Const
 
-    // Base is Base=Var+Const ==>
-    //   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
-
     // Index is Index=Var+Const ==>
     //   set Index=Var, Offset+=(Const<<Shift)
 
@@ -4039,7 +4057,7 @@
 
 template <> void ConstantInteger::emit(GlobalContext *Ctx) const {
   Ostream &Str = Ctx->getStrEmit();
-  Str << getValue();
+  Str << (int64_t) getValue();
 }
 
 template <> void ConstantFloat::emit(GlobalContext *Ctx) const {