[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()) &&
+            cast<BranchInst>(I->getNextNode())->isUnconditional());
----------------
david-arm wrote:

Also, just for my understanding why do we only care about treating instructions like select if they are at the end of the block? From the name of the function `shouldTreatInstructionLikeSelect` it sounds like we should always treat `or(zext(c),y` like a select. I guess the function is really asking the question - "should we convert this like select-like instruction into compare-and-branch?". So I sympathise with you and it's hard to put that mouthful into a succint function name!

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


More information about the llvm-commits mailing list