Fix tautological-compare warnings.

This commit is contained in:
Wilson Snyder
2024-02-07 22:16:08 -05:00
parent e2e0795538
commit efff630763
5 changed files with 67 additions and 5 deletions
+11 -5
View File
@@ -1441,16 +1441,22 @@ class ConstVisitor final : public VNVisitor {
static bool operandsSame(AstNode* node1p, AstNode* node2p) {
// For now we just detect constants & simple vars, though it could be more generic
if (VN_IS(node1p, Const) && VN_IS(node2p, Const)) {
return node1p->sameGateTree(node2p);
} else if (VN_IS(node1p, VarRef) && VN_IS(node2p, VarRef)) {
if (VN_IS(node1p, Const) && VN_IS(node2p, Const)) return node1p->sameGateTree(node2p);
if (VN_IS(node1p, VarRef) && VN_IS(node2p, VarRef)) {
// Avoid comparing widthMin's, which results in lost optimization attempts
// If cleanup sameGateTree to be smarter, this can be restored.
// return node1p->sameGateTree(node2p);
return node1p->isSame(node2p);
} else {
return false;
}
// Pattern created by coverage-line; avoid compiler tautological-compare warning
if (AstAnd* const and1p = VN_CAST(node1p, And)) {
if (AstAnd* const and2p = VN_CAST(node2p, And)) {
if (VN_IS(and1p->lhsp(), Const) && VN_IS(and1p->rhsp(), NodeVarRef)
&& VN_IS(and2p->lhsp(), Const) && VN_IS(and2p->rhsp(), NodeVarRef))
return node1p->sameGateTree(node2p);
}
}
return false;
}
bool ifSameAssign(const AstNodeIf* nodep) {
const AstNodeAssign* const thensp = VN_CAST(nodep->thensp(), NodeAssign);