[NFC][SCEVExpander] `CmpSelCost`: use the cost of the expression, not operand
authorRoman Lebedev <lebedev.ri@gmail.com>
Sun, 22 Jan 2023 14:27:17 +0000 (17:27 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sun, 22 Jan 2023 14:48:49 +0000 (17:48 +0300)
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.

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

index 5a0292a..24f1966 100644 (file)
@@ -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);