[clang] [IPSCCP] Variable not visible at Og. (PR #66745)

Felipe de Azevedo Piovezan via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 4 15:16:26 PDT 2023


================
@@ -106,14 +107,71 @@ static void findReturnsToZap(Function &F,
   }
 }
 
-static bool runIPSCCP(
-    Module &M, const DataLayout &DL, FunctionAnalysisManager *FAM,
-    std::function<const TargetLibraryInfo &(Function &)> GetTLI,
-    std::function<TargetTransformInfo &(Function &)> GetTTI,
-    std::function<AssumptionCache &(Function &)> GetAC,
-    std::function<DominatorTree &(Function &)> GetDT,
-    std::function<BlockFrequencyInfo &(Function &)> GetBFI,
-    bool IsFuncSpecEnabled) {
+static void createDebugConstantExpression(Module &M, GlobalVariable *GV) {
+  SmallVector<DIGlobalVariableExpression *, 1> GVEs;
+  GV->getDebugInfo(GVEs);
+  if (GVEs.size() != 1)
+    return;
+
+  DIBuilder DIB(M);
+
+  // Create integer constant expression.
+  auto createIntegerExpression = [&DIB](const Constant *CV) -> DIExpression * {
+    const APInt &API = cast<ConstantInt>(CV)->getValue();
+    std::optional<uint64_t> InitIntOpt;
+    if (API.isNonNegative())
+      InitIntOpt = API.tryZExtValue();
+    else if (auto Temp = API.trySExtValue())
+      // Transform a signed optional to unsigned optional.
+      InitIntOpt = static_cast<uint64_t>(*Temp);
----------------
felipepiovezan wrote:

Looking at this again, isn't this the equivalent of always doing a sign extension?
We are basically saying: if this starts with a zero, add zeros; if this starts with a one, add ones.
Unless I am missing something, this code could be:

```
if (std::optional<sint64_t> InitIntOpt = API.trySExtValue())
   return DIB.createConstantValueExpression(static_cast<uint64_t>(*InitIntOpt))

return nullptr;
```

https://github.com/llvm/llvm-project/pull/66745


More information about the cfe-commits mailing list