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
// is pretty loose.
if (const auto *LInst = dyn_cast<Instruction>(LV)) {
std::unique_ptr<Module> M = parseAssemblyString(
"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) "
" local_unnamed_addr { "
"entry: "
" %y = load i32, i32* %Y "
" %z = load i32, i32* %Z "
" ret void "
- "} ",
+ "} "
+ " "
+ " "
+ "define void @f_3() { "
+ " %x = load i32, i32* @var_0"
+ " %y = load i32, i32* @var_1"
+ " ret void"
+ "} "
+ ,
Err, C);
assert(M && "Could not parse module?");
EXPECT_EQ(Mul3, Mul4);
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