[llvm] r252879 - [InstCombine] Add trivial folding (bitreverse (bitreverse x)) -> x

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 12 05:18:37 PST 2015


----- Original Message -----
> From: "James Molloy via llvm-commits" <llvm-commits at lists.llvm.org>
> To: llvm-commits at lists.llvm.org
> Sent: Thursday, November 12, 2015 6:39:41 AM
> Subject: [llvm] r252879 - [InstCombine] Add trivial folding (bitreverse (bitreverse x)) -> x
> 
> Author: jamesm
> Date: Thu Nov 12 06:39:41 2015
> New Revision: 252879
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=252879&view=rev
> Log:
> [InstCombine] Add trivial folding (bitreverse (bitreverse x)) -> x
> 
> There are plenty more instcombines we could probably do with
> bitreverse, but this seems like a very obvious and trivial starting
> point and was brought up by Hal in his review.

Also, while I'm thinking about it, we'll need constant-folding support and known-bits support.

 -Hal

> 
> Added:
>     llvm/trunk/test/Transforms/InstCombine/bitreverse-fold.ll
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=252879&r1=252878&r2=252879&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu
> Nov 12 06:39:41 2015
> @@ -788,6 +788,16 @@ Instruction *InstCombiner::visitCallInst
>      break;
>    }
>  
> +  case Intrinsic::bitreverse: {
> +    Value *IIOperand = II->getArgOperand(0);
> +    Value *X = nullptr;
> +
> +    // bitreverse(bitreverse(x)) -> x
> +    if (match(IIOperand,
> m_Intrinsic<Intrinsic::bitreverse>(m_Value(X))))
> +      return ReplaceInstUsesWith(CI, X);
> +    break;
> +  }
> +
>    case Intrinsic::powi:
>      if (ConstantInt *Power =
>      dyn_cast<ConstantInt>(II->getArgOperand(1))) {
>        // powi(x, 0) -> 1.0
> 
> Added: llvm/trunk/test/Transforms/InstCombine/bitreverse-fold.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bitreverse-fold.ll?rev=252879&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/bitreverse-fold.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/bitreverse-fold.ll Thu Nov
> 12 06:39:41 2015
> @@ -0,0 +1,11 @@
> +; RUN: opt < %s -instcombine -S | FileCheck %s
> +
> +define i32 @test1(i32 %p) {
> +; CHECK-LABEL: @test1
> +; CHECK-NEXT: ret i32 %p
> +  %a = call i32 @llvm.bitreverse.i32(i32 %p)
> +  %b = call i32 @llvm.bitreverse.i32(i32 %a)
> +  ret i32 %b
> +}
> +
> +declare i32 @llvm.bitreverse.i32(i32) readnone
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory


More information about the llvm-commits mailing list