[Mlir-commits] [llvm] [mlir] [OpenMP][CodeExtractor]Add align metadata to load instructions (PR #131131)

Dominik Adamski llvmlistbot at llvm.org
Tue Apr 8 05:51:52 PDT 2025


================
@@ -1612,8 +1625,31 @@ void CodeExtractor::emitFunctionBody(
       Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), aggIdx);
       GetElementPtrInst *GEP = GetElementPtrInst::Create(
           StructArgTy, AggArg, Idx, "gep_" + inputs[i]->getName(), newFuncRoot);
-      RewriteVal = new LoadInst(StructArgTy->getElementType(aggIdx), GEP,
-                                "loadgep_" + inputs[i]->getName(), newFuncRoot);
+      LoadInst *LoadGEP =
+          new LoadInst(StructArgTy->getElementType(aggIdx), GEP,
+                       "loadgep_" + inputs[i]->getName(), newFuncRoot);
+      if (StructArgTy->getElementType(aggIdx)->isPointerTy()) {
+        unsigned AlignmentValue;
+        const Triple &TargetTriple =
+            newFunction->getParent()->getTargetTriple();
+        const DataLayout &DL = header->getDataLayout();
+        // Pointers without casting can provide more information about
+        // alignment. Use pointers without casts if given target preserves
+        // alignment information for cast the operation.
+        if (isAlignmentPreservedForAddrCast(TargetTriple))
+          AlignmentValue =
+              inputs[i]->stripPointerCasts()->getPointerAlignment(DL).value();
----------------
DominikAdamski wrote:

The `getPointerAlignment` function is from the `Value` class. Do you think it's worth adding another version of this function to this basic class? If yes, I will create a separate patch that will contain a version of the `getPointerAlignment` function with two arguments. One of them will be a flag to get the value alignment without pointer casts.

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


More information about the Mlir-commits mailing list