]> granicus.if.org Git - llvm/commitdiff
[InstCombine] use 'match' and other clean-up; NFCI
authorSanjay Patel <spatel@rotateright.com>
Fri, 13 Jan 2017 18:52:10 +0000 (18:52 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 13 Jan 2017 18:52:10 +0000 (18:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineShifts.cpp

index a79a630e5ecf7510a672799ee74bbd4826b48591..5209dad31b586867735b26974ef812b63f318450 100644 (file)
@@ -727,23 +727,14 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
   if (match(Op1, m_APInt(ShAmtAPInt))) {
     unsigned ShAmt = ShAmtAPInt->getZExtValue();
 
-    // Turn:
-    //  %zext = zext i32 %V to i64
-    //  %res = shl i64 %V, 8
-    //
-    // Into:
-    //  %shl = shl i32 %V, 8
-    //  %res = zext i32 %shl to i64
-    //
-    // This is only valid if %V would have zeros shifted out.
-    if (auto *ZI = dyn_cast<ZExtInst>(Op0)) {
-      unsigned SrcBitWidth = ZI->getSrcTy()->getScalarSizeInBits();
-      if (ShAmt < SrcBitWidth &&
-          MaskedValueIsZero(ZI->getOperand(0),
-                            APInt::getHighBitsSet(SrcBitWidth, ShAmt), 0, &I)) {
-        auto *Shl = Builder->CreateShl(ZI->getOperand(0), ShAmt);
-        return new ZExtInst(Shl, I.getType());
-      }
+    // shl (zext X), ShAmt --> zext (shl X, ShAmt)
+    // This is only valid if X would have zeros shifted out.
+    Value *X;
+    if (match(Op0, m_ZExt(m_Value(X)))) {
+      unsigned SrcWidth = X->getType()->getScalarSizeInBits();
+      if (ShAmt < SrcWidth &&
+          MaskedValueIsZero(X, APInt::getHighBitsSet(SrcWidth, ShAmt), 0, &I))
+        return new ZExtInst(Builder->CreateShl(X, ShAmt), I.getType());
     }
 
     // If the shifted-out value is known-zero, then this is a NUW shift.