[PATCH] D152349: [InstCombine] Canonicalize (icmp eq/ne X, rotate(X)) to always use rotate-left
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 12:36:37 PDT 2023
goldstein.w.n updated this revision to Diff 529406.
goldstein.w.n added a comment.
Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152349/new/
https://reviews.llvm.org/D152349
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll
Index: llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp-equality-rotate.ll
+++ 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]]
;
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ 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<Intrinsic::fshr>(
+ 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152349.529406.patch
Type: text/x-patch
Size: 2221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230607/57e4c9dc/attachment.bin>
More information about the llvm-commits
mailing list