[PATCH] D36743: [InstCombine] Added support for (X >>s C) << C --> X & (-1 << C)

Amjad Aboud via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 08:20:00 PDT 2017


aaboud created this revision.

This patch is needed for https://reviews.llvm.org/D36679.


https://reviews.llvm.org/D36743

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


Index: lib/Transforms/InstCombine/InstCombineShifts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -559,8 +559,8 @@
         return new ZExtInst(Builder.CreateShl(X, ShAmt), Ty);
     }
 
-    // (X >>u C) << C --> X & (-1 << C)
-    if (match(Op0, m_LShr(m_Value(X), m_Specific(Op1)))) {
+    // (X >> C) << C --> X & (-1 << C)
+    if (match(Op0, m_Shr(m_Value(X), m_Specific(Op1)))) {
       APInt Mask(APInt::getHighBitsSet(BitWidth, BitWidth - ShAmt));
       return BinaryOperator::CreateAnd(X, ConstantInt::get(Ty, Mask));
     }
Index: test/Transforms/InstCombine/shift.ll
===================================================================
--- test/Transforms/InstCombine/shift.ll
+++ test/Transforms/InstCombine/shift.ll
@@ -221,6 +221,19 @@
   ret i32 %C
 }
 
+;; ((A | 0xC0000000) >> 8) << 8 === (A & 3FFFFF00) | 0xC0000000
+define i32 @test12a(i32 %A) {
+; CHECK-LABEL: @test12a(
+; CHECK-NEXT:    [[a:%.*]] = and i32 %A, 1073741568
+; CHECK-NEXT:    [[C:%.*]] = or i32 [[a]], -1073741824
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %a = or i32 %A, -1073741824
+  %B = ashr i32 %a, 8
+  %C = shl i32 %B, 8
+  ret i32 %C
+}
+
 ;; This transformation is deferred to DAGCombine:
 ;; (A >> 3) << 4 === (A & -8) * 2
 ;; The shl may be valuable to scalar evolution.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36743.111168.patch
Type: text/x-patch
Size: 1430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170815/ebd15cf7/attachment.bin>


More information about the llvm-commits mailing list