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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 00:45:57 PST 2024


================
@@ -412,6 +412,16 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
 
   bool enableSelectOptimize() { return ST->enableSelectOptimize(); }
 
+  bool shouldTreatInstructionLikeSelect(Instruction *I) {
+    // For the binary operators (e.g. or) we need to be more careful than
+    // selects, here we only transform them if they are already at a natural
+    // break point in the code - the end of a block with an unconditional
+    // terminator.
+    return isa<SelectInst>(I) ||
+           (isa<BinaryOperator>(I) && isa<BranchInst>(I->getNextNode()) &&
----------------
david-arm wrote:

Is the next node guaranteed to exist in all cases? I assume a well-formed block should always have a terminator, but I wasn't completely sure. If the next node could be NULL then you'd have to add an extra check before calling `isa`.

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


More information about the llvm-commits mailing list