]> granicus.if.org Git - llvm/commitdiff
[InstCombine] add extra use constraint for shl-zext fold
authorSanjay Patel <spatel@rotateright.com>
Mon, 5 Aug 2019 16:04:07 +0000 (16:04 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 5 Aug 2019 16:04:07 +0000 (16:04 +0000)
As the test shows, we can end up with more instructions than
we started with if we don't include the extra-use check.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367880 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineShifts.cpp
test/Transforms/InstCombine/shift.ll

index 2427d795c47652cc359275510f82b4e7b00e1f2d..a30bcbd64cac40ad46530db569e88d4e3dbf4057 100644 (file)
@@ -718,7 +718,7 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
     // 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)))) {
+    if (match(Op0, m_OneUse(m_ZExt(m_Value(X))))) {
       unsigned SrcWidth = X->getType()->getScalarSizeInBits();
       if (ShAmt < SrcWidth &&
           MaskedValueIsZero(X, APInt::getHighBitsSet(SrcWidth, ShAmt), 0, &I))
index eaeecacd44de191d2fab1e01ca50330e150b6b7f..6bb38da87a8c91e239e516e74e39403c6bcebaa9 100644 (file)
@@ -1198,8 +1198,7 @@ define i64 @shl_zext_extra_use(i32 %t) {
 ; CHECK-NEXT:    [[AND:%.*]] = and i32 [[T:%.*]], 16777215
 ; CHECK-NEXT:    [[EXT:%.*]] = zext i32 [[AND]] to i64
 ; CHECK-NEXT:    call void @use(i64 [[EXT]])
-; CHECK-NEXT:    [[TMP1:%.*]] = shl i32 [[T]], 8
-; CHECK-NEXT:    [[SHL:%.*]] = zext i32 [[TMP1]] to i64
+; CHECK-NEXT:    [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 8
 ; CHECK-NEXT:    ret i64 [[SHL]]
 ;
   %and = and i32 %t, 16777215