mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-22 10:29:35 +00:00
implement the transform requested in PR5284
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92398 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bfdfea86a1
commit
e33d413152
@ -10139,6 +10139,19 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||
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))) {
|
||||
|
@ -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 @@ entry:
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user