[llvm] [SelectOpt] Add handling for Select-like operations. (PR #77284)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 13:12:07 PST 2024
================
@@ -129,6 +124,146 @@ class SelectOptimizeImpl {
Scaled64 NonPredCost;
};
+ /// SelectLike is an abstraction over SelectInst and other operations that can
+ /// act like selects. For example Or(Zext(icmp), X) can be treated like
+ /// select(icmp, X|1, X).
+ class SelectLike {
+ private:
+ SelectLike(Instruction *I) : I(I) {}
+
+ Instruction *I;
+
+ public:
+ /// Match a select or select-like instruction, returning a SelectLike.
+ static SelectLike match(Instruction *I) {
+ // Select instruction are what we are usually looking for.
+ if (isa<SelectInst>(I))
+ return SelectLike(I);
+
+ // An Or(zext(i1 X), Y) can also be treated like a select, with condition
+ // C and values Y|1 and Y.
+ Value *X;
+ if (PatternMatch::match(
----------------
fhahn wrote:
is `PatternMatch::` needed with `using namespace llvm::PatternMatch;` above?
https://github.com/llvm/llvm-project/pull/77284
More information about the llvm-commits
mailing list