Skip to content

Commit

Permalink
[NFC][ScalarEvolution] Fix SCEVNAryExpr::getType().
Browse files Browse the repository at this point in the history
SCEVNAryExpr::getType() could return the wrong type for a SCEVAddExpr.
Remove it, and add getType() methods to the relevant subclasses.

NFC because nothing uses it directly, as far as I know; this is just
future-proofing.
  • Loading branch information
efriedma-quic committed Jun 23, 2021
1 parent 9e73f7c commit fdaf304
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
Expand Up @@ -210,8 +210,6 @@ class Type;
return make_range(op_begin(), op_end());
}

Type *getType() const { return getOperand(0)->getType(); }

NoWrapFlags getNoWrapFlags(NoWrapFlags Mask = NoWrapMask) const {
return (NoWrapFlags)(SubclassData & Mask);
}
Expand Down Expand Up @@ -293,6 +291,8 @@ class Type;
: SCEVCommutativeExpr(ID, scMulExpr, O, N) {}

public:
Type *getType() const { return getOperand(0)->getType(); }

/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const SCEV *S) {
return S->getSCEVType() == scMulExpr;
Expand Down Expand Up @@ -359,6 +359,7 @@ class Type;
: SCEVNAryExpr(ID, scAddRecExpr, O, N), L(l) {}

public:
Type *getType() const { return getStart()->getType(); }
const SCEV *getStart() const { return Operands[0]; }
const Loop *getLoop() const { return L; }

Expand Down Expand Up @@ -445,6 +446,8 @@ class Type;
}

public:
Type *getType() const { return getOperand(0)->getType(); }

static bool classof(const SCEV *S) {
return isMinMaxType(S->getSCEVType());
}
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Analysis/ScalarEvolution.cpp
Expand Up @@ -386,12 +386,14 @@ Type *SCEV::getType() const {
case scSignExtend:
return cast<SCEVCastExpr>(this)->getType();
case scAddRecExpr:
return cast<SCEVAddRecExpr>(this)->getType();
case scMulExpr:
return cast<SCEVMulExpr>(this)->getType();
case scUMaxExpr:
case scSMaxExpr:
case scUMinExpr:
case scSMinExpr:
return cast<SCEVNAryExpr>(this)->getType();
return cast<SCEVMinMaxExpr>(this)->getType();
case scAddExpr:
return cast<SCEVAddExpr>(this)->getType();
case scUDivExpr:
Expand Down

0 comments on commit fdaf304

Please sign in to comment.