[PATCH] Remove redundant folding of bswap(bswap(x))

Matt Arsenault Matthew.Arsenault at amd.com
Wed Aug 13 09:59:14 PDT 2014


Idempotent intrinsics are already generally handled, so no need to special case bswap.

http://reviews.llvm.org/D4887

Files:
  lib/Analysis/InstructionSimplify.cpp
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstSimplify/call.ll

Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -3009,6 +3009,7 @@
   case Intrinsic::rint:
   case Intrinsic::nearbyint:
   case Intrinsic::round:
+  case Intrinsic::bswap:
     return true;
   }
 }
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -284,10 +284,6 @@
     Value *IIOperand = II->getArgOperand(0);
     Value *X = nullptr;
 
-    // bswap(bswap(x)) -> x
-    if (match(IIOperand, m_BSwap(m_Value(X))))
-        return ReplaceInstUsesWith(CI, X);
-
     // bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
     if (match(IIOperand, m_Trunc(m_BSwap(m_Value(X))))) {
       unsigned C = X->getType()->getPrimitiveSizeInBits() -
Index: test/Transforms/InstSimplify/call.ll
===================================================================
--- test/Transforms/InstSimplify/call.ll
+++ test/Transforms/InstSimplify/call.ll
@@ -102,6 +102,17 @@
   ret float %r4
 }
 
+declare i32 @llvm.bswap.i32(i32) nounwind readnone
+
+; CHECK-LABEL: @test_idempotence_2(
+; CHECK: bswap
+; CHECK-NOT: bswap
+define i32 @test_idempotence_2(i32 %a) {
+  %a0 = call i32 @llvm.bswap.i32(i32 %a)
+  %a1 = call i32 @llvm.bswap.i32(i32 %a0)
+  ret i32 %a1
+}
+
 define i8* @operator_new() {
 entry:
   %call = tail call noalias i8* @_Znwm(i64 8)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4887.12460.patch
Type: text/x-patch
Size: 1561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140813/0e3a044a/attachment.bin>


More information about the llvm-commits mailing list