forked from OSchip/llvm-project
[InstCombine] look through bswap/bitreverse for equality comparisons
I noticed this missed bswap optimization in the CGP memcmp() expansion, and then I saw that we don't have the fold in InstCombine. Differential Revision: https://reviews.llvm.org/D34763 llvm-svn: 306980
This commit is contained in:
parent
91a00b974d
commit
c3d5cf0bb7
|
@ -3438,6 +3438,15 @@ Instruction *InstCombiner::foldICmpEquality(ICmpInst &I) {
|
|||
}
|
||||
}
|
||||
|
||||
// If both operands are byte-swapped or bit-reversed, just compare the
|
||||
// original values.
|
||||
// TODO: Move this to a function similar to foldICmpIntrinsicWithConstant()
|
||||
// and handle more intrinsics.
|
||||
if ((match(Op0, m_BSwap(m_Value(A))) && match(Op1, m_BSwap(m_Value(B)))) ||
|
||||
(match(Op0, m_Intrinsic<Intrinsic::bitreverse>(m_Value(A))) &&
|
||||
match(Op1, m_Intrinsic<Intrinsic::bitreverse>(m_Value(B)))))
|
||||
return new ICmpInst(Pred, A, B);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -2979,9 +2979,7 @@ declare i32 @llvm.bswap.i32(i32)
|
|||
|
||||
define i1 @bswap_ne(i32 %x, i32 %y) {
|
||||
; CHECK-LABEL: @bswap_ne(
|
||||
; CHECK-NEXT: [[SWAPX:%.*]] = call i32 @llvm.bswap.i32(i32 %x)
|
||||
; CHECK-NEXT: [[SWAPY:%.*]] = call i32 @llvm.bswap.i32(i32 %y)
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[SWAPX]], [[SWAPY]]
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 %x, %y
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%swapx = call i32 @llvm.bswap.i32(i32 %x)
|
||||
|
@ -2994,9 +2992,7 @@ declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>)
|
|||
|
||||
define <8 x i1> @bswap_vec_eq(<8 x i16> %x, <8 x i16> %y) {
|
||||
; CHECK-LABEL: @bswap_vec_eq(
|
||||
; CHECK-NEXT: [[SWAPX:%.*]] = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %x)
|
||||
; CHECK-NEXT: [[SWAPY:%.*]] = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %y)
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <8 x i16> [[SWAPX]], [[SWAPY]]
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <8 x i16> %x, %y
|
||||
; CHECK-NEXT: ret <8 x i1> [[CMP]]
|
||||
;
|
||||
%swapx = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %x)
|
||||
|
@ -3009,9 +3005,7 @@ declare i64 @llvm.bitreverse.i64(i64)
|
|||
|
||||
define i1 @bitreverse_eq(i64 %x, i64 %y) {
|
||||
; CHECK-LABEL: @bitreverse_eq(
|
||||
; CHECK-NEXT: [[REVX:%.*]] = call i64 @llvm.bitreverse.i64(i64 %x)
|
||||
; CHECK-NEXT: [[REVY:%.*]] = call i64 @llvm.bitreverse.i64(i64 %y)
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[REVX]], [[REVY]]
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 %x, %y
|
||||
; CHECK-NEXT: ret i1 [[CMP]]
|
||||
;
|
||||
%revx = call i64 @llvm.bitreverse.i64(i64 %x)
|
||||
|
@ -3024,9 +3018,7 @@ declare <8 x i16> @llvm.bitreverse.v8i16(<8 x i16>)
|
|||
|
||||
define <8 x i1> @bitreverse_vec_ne(<8 x i16> %x, <8 x i16> %y) {
|
||||
; CHECK-LABEL: @bitreverse_vec_ne(
|
||||
; CHECK-NEXT: [[REVX:%.*]] = call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> %x)
|
||||
; CHECK-NEXT: [[REVY:%.*]] = call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> %y)
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <8 x i16> [[REVX]], [[REVY]]
|
||||
; CHECK-NEXT: [[CMP:%.*]] = icmp ne <8 x i16> %x, %y
|
||||
; CHECK-NEXT: ret <8 x i1> [[CMP]]
|
||||
;
|
||||
%revx = call <8 x i16> @llvm.bitreverse.v8i16(<8 x i16> %x)
|
||||
|
|
Loading…
Reference in New Issue