[llvm] [clang] split load to bytes to deduce load value (PR #72364)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 01:33:43 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff dedf2c6bb5193652f6ad7d9ff9e676624c2485b7 41a9dbd39fbb866e7fc090f82d58ee6364a7cfda -- clang/test/Frontend/optimization-remark-extra-analysis.c llvm/include/llvm/Transforms/Scalar/GVN.h llvm/lib/Transforms/Scalar/GVN.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index f64508a831..fc0b49bcd9 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2163,10 +2163,10 @@ bool GVNPass::splitAndprocessLoad(LoadInst *L) {
   // we update this byte by byte as we deduce the load value
   APInt ConstructedValue = APInt::getZero(BW);
 
-  for (unsigned i=0; i<BW/8; i++) {
+  for (unsigned i = 0; i < BW / 8; i++) {
     Value *Offset = Constant::getIntegerValue(LTy, APInt(BW, i));
     GetElementPtrInst *GEP = GetElementPtrInst::Create(
-                               ByteTy, Base, ArrayRef<Value*>(Offset), "", L);
+        ByteTy, Base, ArrayRef<Value *>(Offset), "", L);
     LoadInst *ByteLoad = new LoadInst(ByteTy, GEP, "", L);
     ByteLoad->setDebugLoc(L->getDebugLoc());
 
@@ -2186,22 +2186,21 @@ bool GVNPass::splitAndprocessLoad(LoadInst *L) {
     }
 
     auto ByteRes = AnalyzeLoadAvailability(ByteLoad, ByteDep, GEP);
-    // If it doesn't reduce to a constant, give up. Creating the value at runtime by
-    // shifting the bytes is not worth it to remove a load.
-    if (ByteRes &&
-          (ByteRes->isMemIntrinValue() ||
-           (ByteRes->isSimpleValue() &&
-            (isa<ConstantInt>(ByteRes->getSimpleValue()) ||
-             isa<UndefValue>(ByteRes->getSimpleValue()))))) {
-        Value *V = ByteRes->MaterializeAdjustedValue(ByteLoad, ByteLoad, *this);
-        ConstantInt *ByteConst = dyn_cast<ConstantInt>(V);
-        if (!ByteConst) {
-          // replace undef with 0. This helps optimize cases where some bits of
-          // load are constant integer, and some are undef. So we can optimize
-          // the load to a particular integer.
-          ByteConst = ConstantInt::get(ByteTy, 0);
-        }
-        ConstructedValue.insertBits(ByteConst->getValue(), 8*i);
+    // If it doesn't reduce to a constant, give up. Creating the value at
+    // runtime by shifting the bytes is not worth it to remove a load.
+    if (ByteRes && (ByteRes->isMemIntrinValue() ||
+                    (ByteRes->isSimpleValue() &&
+                     (isa<ConstantInt>(ByteRes->getSimpleValue()) ||
+                      isa<UndefValue>(ByteRes->getSimpleValue()))))) {
+      Value *V = ByteRes->MaterializeAdjustedValue(ByteLoad, ByteLoad, *this);
+      ConstantInt *ByteConst = dyn_cast<ConstantInt>(V);
+      if (!ByteConst) {
+        // replace undef with 0. This helps optimize cases where some bits of
+        // load are constant integer, and some are undef. So we can optimize
+        // the load to a particular integer.
+        ByteConst = ConstantInt::get(ByteTy, 0);
+      }
+      ConstructedValue.insertBits(ByteConst->getValue(), 8 * i);
     } else {
       LLVM_DEBUG(dbgs() << "GVN split load: byte " << i
                         << " did not reduce to a constant. Giving up");

``````````

</details>


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


More information about the cfe-commits mailing list