[llvm] 670e60c - [InstCombine] Add partial bswap test from D88578

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 02:34:57 PDT 2020


Author: Simon Pilgrim
Date: 2020-10-02T10:34:30+01:00
New Revision: 670e60c0238bb8e9fb39947017dc3b5459c8ee60

URL: https://github.com/llvm/llvm-project/commit/670e60c0238bb8e9fb39947017dc3b5459c8ee60
DIFF: https://github.com/llvm/llvm-project/commit/670e60c0238bb8e9fb39947017dc3b5459c8ee60.diff

LOG: [InstCombine] Add partial bswap test from D88578

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/bswap.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/bswap.ll b/llvm/test/Transforms/InstCombine/bswap.ll
index 8adcb748b96f..4c6e3dd9a2ff 100644
--- a/llvm/test/Transforms/InstCombine/bswap.ll
+++ b/llvm/test/Transforms/InstCombine/bswap.ll
@@ -345,6 +345,28 @@ define i8 @PR39793_bswap_u32_as_u16_trunc(i32 %0) {
   ret i8 %7
 }
 
+define i32 @partial_bswap(i32 %x) {
+; CHECK-LABEL: @partial_bswap(
+; CHECK-NEXT:    [[X3:%.*]] = shl i32 [[X:%.*]], 24
+; CHECK-NEXT:    [[A2:%.*]] = shl i32 [[X]], 8
+; CHECK-NEXT:    [[X2:%.*]] = and i32 [[A2]], 16711680
+; CHECK-NEXT:    [[X32:%.*]] = or i32 [[X3]], [[X2]]
+; CHECK-NEXT:    [[T1:%.*]] = and i32 [[X]], -65536
+; CHECK-NEXT:    [[T2:%.*]] = call i32 @llvm.bswap.i32(i32 [[T1]])
+; CHECK-NEXT:    [[R:%.*]] = or i32 [[X32]], [[T2]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %x3 = shl i32 %x, 24
+  %a2 = shl i32 %x, 8
+  %x2 = and i32 %a2, 16711680
+  %x32 = or i32 %x3, %x2
+  %t1 = and i32 %x, -65536
+  %t2 = call i32 @llvm.bswap.i32(i32 %t1)
+  %r = or i32 %x32, %t2
+  ret i32 %r
+}
+declare i32 @llvm.bswap.i32(i32)
+
 define i64 @bswap_and_mask_0(i64 %0) {
 ; CHECK-LABEL: @bswap_and_mask_0(
 ; CHECK-NEXT:    [[TMP2:%.*]] = lshr i64 [[TMP0:%.*]], 56


        


More information about the llvm-commits mailing list