[PATCH] D150360: [InstCombine] Optimize compares with multiple selects as operands
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 24 06:56:58 PDT 2023
nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.
Looks pretty reasonable.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6596-6597
+ if (match(Op0, m_Select(m_Value(Cond1), m_Value(A), m_Value(B))) &&
+ match(Op1, m_Select(m_Value(Cond2), m_Value(C), m_Value(D))) &&
+ Cond1 == Cond2) {
+ // Check whether comparison of TrueValues can be simplified
----------------
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6600
+ if (Value *Res = simplifyICmpInst(Pred, A, C, SQ)) {
+ Builder.SetInsertPoint(&I);
+ Value *NewICMP = Builder.CreateICmp(Pred, B, D);
----------------
Setting the insertion point is unnecessary.
================
Comment at: llvm/test/Transforms/InstCombine/icmp-with-selects.ll:4
+
+define i1 @_Z3fooib(i32 noundef %param, i1 noundef zeroext %cond) {
+; CHECK-LABEL: define i1 @_Z3fooib
----------------
Drop the noundef and zeroext parameters.
================
Comment at: llvm/test/Transforms/InstCombine/icmp-with-selects.ll:77
+}
+
----------------
Add negative tests:
1. Select conditions are not the same.
2. Neither side simplifies.
Also add multi-use tests, where one/both selects have additional uses. You'll find that you need to add some one-use checks.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150360/new/
https://reviews.llvm.org/D150360
More information about the llvm-commits
mailing list