[llvm-bugs] [Bug 33143] New: Semantics of address taken for Global Variables (GV)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 23 09:43:57 PDT 2017


            Bug ID: 33143
           Summary: Semantics of address taken for Global Variables (GV)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Interprocedural Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: davide at freebsd.org
                CC: filcab at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, rafael.espindola at gmail.com

Interprocedural optimizations sometimes leverage that a function or a GVs has
not its address taken to perform more aggressive optimizations, e.g. SCCP keeps
track of internal GVs with addres not taken to propagate constants.

Some passes, SCCP in particular, roll their own checking for `AddressIsTaken`.
For functions, we should just use `F.hasAddressTaken()`, but there seems to not
be an equivalent for GVs.
I think the semantics of "addressTaken" for GVs need to be clarified, and
`hasAddressTaken` should a member variable of GV.

This would allow us to remove the following hack:

static bool AddressIsTaken(const GlobalValue *GV) {
  // Delete any dead constantexpr klingons.

  for (const Use &U : GV->uses()) {
    const User *UR = U.getUser();
    if (const auto *SI = dyn_cast<StoreInst>(UR)) {
      if (SI->getOperand(0) == GV || SI->isVolatile())
        return true;  // Storing addr of GV.
    } else if (isa<InvokeInst>(UR) || isa<CallInst>(UR)) {
      // Make sure we are calling the function, not passing the address.
      ImmutableCallSite CS(cast<Instruction>(UR));
      if (!CS.isCallee(&U))
        return true;
    } else if (const auto *LI = dyn_cast<LoadInst>(UR)) {
      if (LI->isVolatile())
        return true;
    } else if (isa<BlockAddress>(UR)) {
      // blockaddress doesn't take the address of the function, it takes addr
      // of label.
    } else {
      return true;
  return false;

and use the function in `GV` instead.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170523/268b1af8/attachment.html>

More information about the llvm-bugs mailing list