forked from OSchip/llvm-project
[SCEV] In CompareValueComplexity, order global values by their name
llvm-svn: 285529
This commit is contained in:
parent
b4830a84b9
commit
299e67291c
|
@ -477,6 +477,21 @@ static int CompareValueComplexity(const LoopInfo *const LI, Value *LV,
|
||||||
return (int)LArgNo - (int)RArgNo;
|
return (int)LArgNo - (int)RArgNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (const auto *LGV = dyn_cast<GlobalValue>(LV)) {
|
||||||
|
const auto *RGV = cast<GlobalValue>(RV);
|
||||||
|
|
||||||
|
const auto IsGVNameSemantic = [&](const GlobalValue *GV) {
|
||||||
|
auto LT = GV->getLinkage();
|
||||||
|
return !(GlobalValue::isPrivateLinkage(LT) ||
|
||||||
|
GlobalValue::isInternalLinkage(LT));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use the names to distinguish the two values, but only if the
|
||||||
|
// names are semantically important.
|
||||||
|
if (IsGVNameSemantic(LGV) && IsGVNameSemantic(RGV))
|
||||||
|
return LGV->getName().compare(RGV->getName());
|
||||||
|
}
|
||||||
|
|
||||||
// For instructions, compare their loop depth, and their operand count. This
|
// For instructions, compare their loop depth, and their operand count. This
|
||||||
// is pretty loose.
|
// is pretty loose.
|
||||||
if (const auto *LInst = dyn_cast<Instruction>(LV)) {
|
if (const auto *LInst = dyn_cast<Instruction>(LV)) {
|
||||||
|
|
|
@ -346,6 +346,9 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
|
||||||
std::unique_ptr<Module> M = parseAssemblyString(
|
std::unique_ptr<Module> M = parseAssemblyString(
|
||||||
"target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\" "
|
"target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\" "
|
||||||
" "
|
" "
|
||||||
|
"@var_0 = external global i32, align 4"
|
||||||
|
"@var_1 = external global i32, align 4"
|
||||||
|
" "
|
||||||
"define void @f_1(i8* nocapture %arr, i32 %n, i32* %A, i32* %B) "
|
"define void @f_1(i8* nocapture %arr, i32 %n, i32* %A, i32* %B) "
|
||||||
" local_unnamed_addr { "
|
" local_unnamed_addr { "
|
||||||
"entry: "
|
"entry: "
|
||||||
|
@ -381,7 +384,15 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
|
||||||
" %y = load i32, i32* %Y "
|
" %y = load i32, i32* %Y "
|
||||||
" %z = load i32, i32* %Z "
|
" %z = load i32, i32* %Z "
|
||||||
" ret void "
|
" ret void "
|
||||||
"} ",
|
"} "
|
||||||
|
" "
|
||||||
|
" "
|
||||||
|
"define void @f_3() { "
|
||||||
|
" %x = load i32, i32* @var_0"
|
||||||
|
" %y = load i32, i32* @var_1"
|
||||||
|
" ret void"
|
||||||
|
"} "
|
||||||
|
,
|
||||||
Err, C);
|
Err, C);
|
||||||
|
|
||||||
assert(M && "Could not parse module?");
|
assert(M && "Could not parse module?");
|
||||||
|
@ -439,6 +450,20 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
|
||||||
EXPECT_EQ(Mul3, Mul4);
|
EXPECT_EQ(Mul3, Mul4);
|
||||||
EXPECT_EQ(Mul4, Mul5);
|
EXPECT_EQ(Mul4, Mul5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto *F = M->getFunction("f_3");
|
||||||
|
ASSERT_NE(F, nullptr);
|
||||||
|
|
||||||
|
ScalarEvolution SE = buildSE(*F);
|
||||||
|
auto *LoadArg0 = SE.getSCEV(getInstructionByName(*F, "x"));
|
||||||
|
auto *LoadArg1 = SE.getSCEV(getInstructionByName(*F, "y"));
|
||||||
|
|
||||||
|
auto *MulA = SE.getMulExpr(LoadArg0, LoadArg1);
|
||||||
|
auto *MulB = SE.getMulExpr(LoadArg1, LoadArg0);
|
||||||
|
|
||||||
|
EXPECT_EQ(MulA, MulB) << "MulA = " << *MulA << ", MulB = " << *MulB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
Loading…
Reference in New Issue