[llvm] 3c560dd - [NFC][SCEVExpander] `CmpSelCost`: use the cost of the expression, not operand

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 06:49:16 PST 2023


Author: Roman Lebedev
Date: 2023-01-22T17:48:49+03:00
New Revision: 3c560dd0ae676e28a2560b1041c9411908e999a5

URL: https://github.com/llvm/llvm-project/commit/3c560dd0ae676e28a2560b1041c9411908e999a5
DIFF: https://github.com/llvm/llvm-project/commit/3c560dd0ae676e28a2560b1041c9411908e999a5.diff

LOG: [NFC][SCEVExpander] `CmpSelCost`: use the cost of the expression, not operand

Currently, for all invocations, it's equivalent, since that is literally
how `SCEVMinMaxExpr::getType()` is defined. But for e.g. `select`,
we'll want to ask about the hand type, and not the type of the operand
that happens to be first.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 5a0292a9c87e..24f1966edd37 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -2113,7 +2113,7 @@ template<typename T> static InstructionCost costAndCollectOperands(
   auto CmpSelCost = [&](unsigned Opcode, unsigned NumRequired, unsigned MinIdx,
                         unsigned MaxIdx) -> InstructionCost {
     Operations.emplace_back(Opcode, MinIdx, MaxIdx);
-    Type *OpType = S->getOperand(0)->getType();
+    Type *OpType = S->getType();
     return NumRequired * TTI.getCmpSelInstrCost(
                              Opcode, OpType, CmpInst::makeCmpResultType(OpType),
                              CmpInst::BAD_ICMP_PREDICATE, CostKind);


        


More information about the llvm-commits mailing list