Subzero: A few fixes toward running larger programs.

1. Add 'llvm2ice -disable-globals' to disable Subzero translation of
global initializers, since full support isn't yet implemented.

2. Change the names of intra-block branch target labels to avoid
collisions with basic block labels.

3. Fix lowering of "br i1 <constant>, label ...", which was producing
invalid instructions like "cmp 1, 0".

4. Fix the "make format-diff" operation, which was diffing against the wrong target.

BUG= none
R=wala@chromium.org

Review URL: https://codereview.chromium.org/449093002
diff --git a/Makefile.standalone b/Makefile.standalone
index 2d3c0ad..4371f2d 100644
--- a/Makefile.standalone
+++ b/Makefile.standalone
@@ -103,7 +103,7 @@
   CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py
 endif
 format-diff:
-	git diff -U0 HEAD^ | \
+	git diff -U0 `git merge-base HEAD master` | \
 	$(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i
 
 clean:
diff --git a/src/IceClFlags.h b/src/IceClFlags.h
index 55e2652..5f4f5aa 100644
--- a/src/IceClFlags.h
+++ b/src/IceClFlags.h
@@ -20,10 +20,11 @@
 public:
   ClFlags()
       : DisableInternal(false), SubzeroTimingEnabled(false),
-        DisableTranslation(false) {}
+        DisableTranslation(false), DisableGlobals(false) {}
   bool DisableInternal;
   bool SubzeroTimingEnabled;
   bool DisableTranslation;
+  bool DisableGlobals;
 };
 }
 
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 9f4c1d8..106b809 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -681,7 +681,8 @@
 namespace Ice {
 
 void Converter::convertToIce(Module *Mod) {
-  convertGlobals(Mod);
+  if (!Flags.DisableGlobals)
+    convertGlobals(Mod);
   convertFunctions(Mod);
 }
 
diff --git a/src/IceInstX8632.cpp b/src/IceInstX8632.cpp
index c30c9f5..cf99e844 100644
--- a/src/IceInstX8632.cpp
+++ b/src/IceInstX8632.cpp
@@ -122,7 +122,7 @@
 IceString InstX8632Label::getName(const Cfg *Func) const {
   char buf[30];
   snprintf(buf, llvm::array_lengthof(buf), "%u", Number);
-  return ".L" + Func->getFunctionName() + "$__" + buf;
+  return ".L" + Func->getFunctionName() + "$local$__" + buf;
 }
 
 InstX8632Br::InstX8632Br(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse,
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index a5704b5..8e56a10 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -1584,7 +1584,7 @@
   if (Inst->isUnconditional()) {
     _br(Inst->getTargetUnconditional());
   } else {
-    Operand *Src0 = legalize(Inst->getCondition());
+    Operand *Src0 = legalize(Inst->getCondition(), Legal_Reg | Legal_Mem);
     Constant *Zero = Ctx->getConstantZero(IceType_i32);
     _cmp(Src0, Zero);
     _br(InstX8632Br::Br_ne, Inst->getTargetTrue(), Inst->getTargetFalse());
@@ -2481,8 +2481,8 @@
   if (InstBr *NextBr = llvm::dyn_cast_or_null<InstBr>(Context.getNextInst())) {
     if (Src0->getType() != IceType_i64 && !NextBr->isUnconditional() &&
         Dest == NextBr->getSrc(0) && NextBr->isLastUse(Dest)) {
-      Operand *Src0New =
-          legalize(Src0, IsSrc1ImmOrReg ? Legal_All : Legal_Reg, true);
+      Operand *Src0New = legalize(
+          Src0, IsSrc1ImmOrReg ? (Legal_Reg | Legal_Mem) : Legal_Reg, true);
       _cmp(Src0New, Src1);
       _br(getIcmp32Mapping(Inst->getCondition()), NextBr->getTargetTrue(),
           NextBr->getTargetFalse());
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp
index bf7de31..dab13f0 100644
--- a/src/llvm2ice.cpp
+++ b/src/llvm2ice.cpp
@@ -88,6 +88,10 @@
 static cl::opt<bool> SubzeroTimingEnabled(
     "timing", cl::desc("Enable breakdown timing of Subzero translation"));
 
+static cl::opt<bool>
+    DisableGlobals("disable-globals",
+                   cl::desc("Disable global initializer translation"));
+
 static cl::opt<NaClFileFormat> InputFileFormat(
     "bitcode-format", cl::desc("Define format of input file:"),
     cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
@@ -128,6 +132,7 @@
   Flags.DisableInternal = DisableInternal;
   Flags.SubzeroTimingEnabled = SubzeroTimingEnabled;
   Flags.DisableTranslation = DisableTranslation;
+  Flags.DisableGlobals = DisableGlobals;
 
   if (BuildOnRead) {
     Ice::PNaClTranslator Translator(&Ctx, Flags);
diff --git a/tests_lit/llvm2ice_tests/branch-simple.ll b/tests_lit/llvm2ice_tests/branch-simple.ll
index 6702790..c054a14 100644
--- a/tests_lit/llvm2ice_tests/branch-simple.ll
+++ b/tests_lit/llvm2ice_tests/branch-simple.ll
@@ -1,7 +1,11 @@
-; Trivial smoke test of compare and branch, with multiple basic
+; 1. Trivial smoke test of compare and branch, with multiple basic
 ; blocks.
+; 2. For a conditional branch on a constant boolean value, make sure
+; we don't lower to a cmp instructions with an immediate as the first
+; source operand.
 
-; RUN: %llvm2ice %s --verbose inst | FileCheck %s
+; RUN: %llvm2ice -O2 --verbose inst %s | FileCheck %s
+; RUN: %llvm2ice -Om1 --verbose inst %s | FileCheck %s
 ; RUN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
 ; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
 ; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
@@ -15,6 +19,7 @@
   ret i32 %foo
 Unequal:
   ret i32 %bar
+; CHECK-LABEL: simple_cond_branch
 ; CHECK: br i1 %r1, label %Equal, label %Unequal
 ; CHECK: Equal:
 ; CHECK:  ret i32 %foo
@@ -22,5 +27,16 @@
 ; CHECK:  ret i32 %bar
 }
 
+define internal i32 @test_br_const() {
+__0:
+  br i1 1, label %__1, label %__2
+__1:
+  ret i32 21
+__2:
+  ret i32 43
+}
+; CHECK-LABEL: test_br_const
+; CHECK-NOT: cmp {{[0-9]*}},
+
 ; ERRORS-NOT: ICE translation error
 ; DUMP-NOT: SZ