Index: lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCompares.cpp +++ lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3437,6 +3437,10 @@ } } + // If both operands are byte-swapped, just compare the original values. + if (match(Op0, m_BSwap(m_Value(A))) && match(Op1, m_BSwap(m_Value(B)))) + return new ICmpInst(Pred, A, B); + return nullptr; } Index: test/Transforms/InstCombine/icmp.ll =================================================================== --- test/Transforms/InstCombine/icmp.ll +++ test/Transforms/InstCombine/icmp.ll @@ -2984,9 +2984,7 @@ 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) @@ -2999,9 +2997,7 @@ 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)