[llvm-commits] [llvm] r92398 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/bswap-fold.ll
Chris Lattner
sabre at nondot.org
Fri Jan 1 10:34:40 PST 2010
Author: lattner
Date: Fri Jan 1 12:34:40 2010
New Revision: 92398
URL: http://llvm.org/viewvc/llvm-project?rev=92398&view=rev
Log:
implement the transform requested in PR5284
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/bswap-fold.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=92398&r1=92397&r2=92398&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jan 1 12:34:40 2010
@@ -10139,6 +10139,19 @@
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(II->getOperand(1)))
if (Operand->getIntrinsicID() == Intrinsic::bswap)
return ReplaceInstUsesWith(CI, Operand->getOperand(1));
+
+ // bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
+ if (TruncInst *TI = dyn_cast<TruncInst>(II->getOperand(1))) {
+ if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(TI->getOperand(0)))
+ if (Operand->getIntrinsicID() == Intrinsic::bswap) {
+ unsigned C = Operand->getType()->getPrimitiveSizeInBits() -
+ TI->getType()->getPrimitiveSizeInBits();
+ Value *CV = ConstantInt::get(Operand->getType(), C);
+ Value *V = Builder->CreateLShr(Operand->getOperand(1), CV);
+ return new TruncInst(V, TI->getType());
+ }
+ }
+
break;
case Intrinsic::powi:
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getOperand(2))) {
Modified: llvm/trunk/test/Transforms/InstCombine/bswap-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bswap-fold.ll?rev=92398&r1=92397&r2=92398&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/bswap-fold.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/bswap-fold.ll Fri Jan 1 12:34:40 2010
@@ -1,23 +1,22 @@
-; RUN: opt < %s -instcombine -S | grep ret | count 6
; RUN: opt < %s -instcombine -S | not grep call.*bswap
define i1 @test1(i16 %tmp2) {
- %tmp10 = call i16 @llvm.bswap.i16( i16 %tmp2 ) ; <i16> [#uses=1]
- %tmp = icmp eq i16 %tmp10, 1 ; <i1> [#uses=1]
+ %tmp10 = call i16 @llvm.bswap.i16( i16 %tmp2 )
+ %tmp = icmp eq i16 %tmp10, 1
ret i1 %tmp
}
define i1 @test2(i32 %tmp) {
- %tmp34 = tail call i32 @llvm.bswap.i32( i32 %tmp ) ; <i32> [#uses=1]
- %tmp.upgrd.1 = icmp eq i32 %tmp34, 1 ; <i1> [#uses=1]
+ %tmp34 = tail call i32 @llvm.bswap.i32( i32 %tmp )
+ %tmp.upgrd.1 = icmp eq i32 %tmp34, 1
ret i1 %tmp.upgrd.1
}
declare i32 @llvm.bswap.i32(i32)
define i1 @test3(i64 %tmp) {
- %tmp34 = tail call i64 @llvm.bswap.i64( i64 %tmp ) ; <i64> [#uses=1]
- %tmp.upgrd.2 = icmp eq i64 %tmp34, 1 ; <i1> [#uses=1]
+ %tmp34 = tail call i64 @llvm.bswap.i64( i64 %tmp )
+ %tmp.upgrd.2 = icmp eq i64 %tmp34, 1
ret i1 %tmp.upgrd.2
}
@@ -50,3 +49,21 @@
ret i32 %tmp4
}
+; PR5284
+declare i64 @llvm.bswap.i64(i64)
+declare i32 @llvm.bswap.i32(i32)
+declare i16 @llvm.bswap.i16(i16)
+
+define i16 @test7(i32 %A) {
+ %B = tail call i32 @llvm.bswap.i32(i32 %A) nounwind
+ %C = trunc i32 %B to i16
+ %D = tail call i16 @llvm.bswap.i16(i16 %C) nounwind
+ ret i16 %D
+}
+
+define i16 @test8(i64 %A) {
+ %B = tail call i64 @llvm.bswap.i64(i64 %A) nounwind
+ %C = trunc i64 %B to i16
+ %D = tail call i16 @llvm.bswap.i16(i16 %C) nounwind
+ ret i16 %D
+}
More information about the llvm-commits
mailing list