Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -3009,6 +3009,7 @@ case Intrinsic::rint: case Intrinsic::nearbyint: case Intrinsic::round: + case Intrinsic::bswap: return true; } } Index: lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCalls.cpp +++ lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -284,10 +284,6 @@ Value *IIOperand = II->getArgOperand(0); Value *X = nullptr; - // bswap(bswap(x)) -> x - if (match(IIOperand, m_BSwap(m_Value(X)))) - return ReplaceInstUsesWith(CI, X); - // bswap(trunc(bswap(x))) -> trunc(lshr(x, c)) if (match(IIOperand, m_Trunc(m_BSwap(m_Value(X))))) { unsigned C = X->getType()->getPrimitiveSizeInBits() - Index: test/Transforms/InstSimplify/call.ll =================================================================== --- test/Transforms/InstSimplify/call.ll +++ test/Transforms/InstSimplify/call.ll @@ -102,6 +102,17 @@ ret float %r4 } +declare i32 @llvm.bswap.i32(i32) nounwind readnone + +; CHECK-LABEL: @test_idempotence_2( +; CHECK: bswap +; CHECK-NOT: bswap +define i32 @test_idempotence_2(i32 %a) { + %a0 = call i32 @llvm.bswap.i32(i32 %a) + %a1 = call i32 @llvm.bswap.i32(i32 %a0) + ret i32 %a1 +} + define i8* @operator_new() { entry: %call = tail call noalias i8* @_Znwm(i64 8)