diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5045,6 +5045,19 @@ return new ICmpInst(CmpInst::getInversePredicate(Pred), Op1, ConstantInt::getNullValue(Op1->getType())); + // Canonicalize: + // icmp eq/ne X, OneUse(rotate-right(X)) + // -> icmp eq/ne X, rotate-left(X) + // We generally try to convert rotate-right -> rotate-left, this just + // canonicalizes another case. + CmpInst::Predicate PredUnused = Pred; + if (match(&I, m_c_ICmp(PredUnused, m_Value(A), + m_OneUse(m_Intrinsic( + m_Deferred(A), m_Deferred(A), m_Value(B)))))) + return new ICmpInst( + Pred, A, + Builder.CreateIntrinsic(Op0->getType(), Intrinsic::fshl, {A, A, B})); + return nullptr; } diff --git a/llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll b/llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll --- a/llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll +++ b/llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll @@ -6,8 +6,8 @@ declare void @use.i8(i8) define i1 @cmpeq_rorr_to_rorl(i8 %x, i8 %C) { ; CHECK-LABEL: @cmpeq_rorr_to_rorl( -; CHECK-NEXT: [[X_RORR:%.*]] = call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[C:%.*]]) -; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[X_RORR]], [[X]] +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[C:%.*]]) +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP1]], [[X]] ; CHECK-NEXT: ret i1 [[R]] ; %x_rorr = call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %C) @@ -42,7 +42,7 @@ define i1 @cmpne_rorr_rorr(i8 %x, i8 %C0, i8 %C1) { ; CHECK-LABEL: @cmpne_rorr_rorr( ; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[C0:%.*]], [[C1:%.*]] -; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[TMP1]]) +; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[TMP1]]) ; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[TMP2]], [[X]] ; CHECK-NEXT: ret i1 [[R]] ;