[llvm] [SelectOpt] Add handling for Select-like operations. (PR #77284)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 07:20:52 PST 2024


================
@@ -129,6 +124,151 @@ 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 *SI) : SI(SI) {}
+
+    Instruction *SI;
+
+  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 the select
+      // is a logical-and/logical-or then it is better treated as a and/or by
+      // the backend.
+      if (isa<SelectInst>(I) &&
+          !PatternMatch::match(I,
----------------
david-arm wrote:

I'm not sure if I've missed something here, but if `I` is a SelectInst how could it pattern match to a `or` or an `and` instruction? It seems like we'll never match.

Also, this type of logic feels like it could live in `shouldTreatInstructionAsSelect`?

https://github.com/llvm/llvm-project/pull/77284


More information about the llvm-commits mailing list