Skip to content

Commit 6d702a1

Browse files
committed
[NewGVN] Prefer poison to undef when ranking operands
ping @alinas
1 parent 52e8f58 commit 6d702a1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,21 +4128,25 @@ bool NewGVN::eliminateInstructions(Function &F) {
41284128
unsigned int NewGVN::getRank(const Value *V) const {
41294129
// Prefer constants to undef to anything else
41304130
// Undef is a constant, have to check it first.
4131+
// Prefer poison to undef as it's less defined.
41314132
// Prefer smaller constants to constantexprs
4133+
// Note that the order here matters because of class inheritance
41324134
if (isa<ConstantExpr>(V))
4133-
return 2;
4134-
if (isa<UndefValue>(V))
4135+
return 3;
4136+
if (isa<PoisonValue>(V))
41354137
return 1;
4138+
if (isa<UndefValue>(V))
4139+
return 2;
41364140
if (isa<Constant>(V))
41374141
return 0;
4138-
else if (auto *A = dyn_cast<Argument>(V))
4139-
return 3 + A->getArgNo();
4142+
if (auto *A = dyn_cast<Argument>(V))
4143+
return 4 + A->getArgNo();
41404144

4141-
// Need to shift the instruction DFS by number of arguments + 3 to account for
4145+
// Need to shift the instruction DFS by number of arguments + 5 to account for
41424146
// the constant and argument ranking above.
41434147
unsigned Result = InstrToDFSNum(V);
41444148
if (Result > 0)
4145-
return 4 + NumFuncArgs + Result;
4149+
return 5 + NumFuncArgs + Result;
41464150
// Unreachable or something else, just return a really large number.
41474151
return ~0;
41484152
}

0 commit comments

Comments
 (0)