Optimize x86 vector shift by constant.

BUG=swiftshader:15

Change-Id: I4b7b97f3de18c201a502d0bc38a2c845a1caf278
Reviewed-on: https://chromium-review.googlesource.com/392627
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Jim Stichnoth <stichnot@chromium.org>
diff --git a/src/IceTargetLoweringX86BaseImpl.h b/src/IceTargetLoweringX86BaseImpl.h
index 9dbf1a9..260366b 100644
--- a/src/IceTargetLoweringX86BaseImpl.h
+++ b/src/IceTargetLoweringX86BaseImpl.h
@@ -2142,9 +2142,27 @@
         llvm::report_fatal_error("Invalid vector multiply type");
       }
     } break;
-    case InstArithmetic::Shl:
-    case InstArithmetic::Lshr:
-    case InstArithmetic::Ashr:
+    case InstArithmetic::Shl: {
+      assert(llvm::isa<Constant>(Src1) && "Non-constant shift not scalarized");
+      Variable *T = makeReg(Ty);
+      _movp(T, Src0);
+      _psll(T, Src1);
+      _movp(Dest, T);
+    } break;
+    case InstArithmetic::Lshr: {
+      assert(llvm::isa<Constant>(Src1) && "Non-constant shift not scalarized");
+      Variable *T = makeReg(Ty);
+      _movp(T, Src0);
+      _psrl(T, Src1);
+      _movp(Dest, T);
+    } break;
+    case InstArithmetic::Ashr: {
+      assert(llvm::isa<Constant>(Src1) && "Non-constant shift not scalarized");
+      Variable *T = makeReg(Ty);
+      _movp(T, Src0);
+      _psra(T, Src1);
+      _movp(Dest, T);
+    } break;
     case InstArithmetic::Udiv:
     case InstArithmetic::Urem:
     case InstArithmetic::Sdiv:
@@ -7009,6 +7027,9 @@
       case InstArithmetic::Shl:
       case InstArithmetic::Lshr:
       case InstArithmetic::Ashr:
+        if (llvm::isa<Constant>(Src1)) {
+          return;
+        }
       case InstArithmetic::Udiv:
       case InstArithmetic::Urem:
       case InstArithmetic::Sdiv: