[llvm] f341807 - [Attributor] Add initial support for vectors in AAPointerInfo

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 23:29:49 PST 2023


Author: Johannes Doerfert
Date: 2023-01-22T23:20:32-08:00
New Revision: f341807ea57d7aa88f0d35c60c5447822e37c1e1

URL: https://github.com/llvm/llvm-project/commit/f341807ea57d7aa88f0d35c60c5447822e37c1e1
DIFF: https://github.com/llvm/llvm-project/commit/f341807ea57d7aa88f0d35c60c5447822e37c1e1.diff

LOG: [Attributor] Add initial support for vectors in AAPointerInfo

While full support requires more work (see TODOs), this allows us to
handle vector writes with a single constant value properly. For now,
we can handle the same constant values stored to all elements if
everything is of a fixed size.

Added: 
    llvm/test/Transforms/Attributor/value-simplify-pointer-info-vec.ll

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index d315ea4262af..377f5160568f 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1352,10 +1352,41 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
 
     // Make a strictly ascending list of offsets as required by addAccess()
     llvm::sort(Offsets);
-    auto Last = std::unique(Offsets.begin(), Offsets.end());
+    auto *Last = std::unique(Offsets.begin(), Offsets.end());
     Offsets.erase(Last, Offsets.end());
 
-    Changed = Changed | addAccess(A, {Offsets, Size}, I, Content, Kind, &Ty);
+    VectorType *VT = dyn_cast<VectorType>(&Ty);
+    if (!VT || VT->getElementCount().isScalable() ||
+        !Content.value_or(nullptr) || !isa<Constant>(*Content) ||
+        (*Content)->getType() != VT ||
+        DL.getTypeStoreSize(VT->getElementType()).isScalable()) {
+      Changed = Changed | addAccess(A, {Offsets, Size}, I, Content, Kind, &Ty);
+    } else {
+      // Handle vector stores with constant content element-wise.
+      // TODO: We could look for the elements or create instructions
+      //       representing them.
+      // TODO: We need to push the Content into the range abstraction
+      //       (AA::RangeTy) to allow 
diff erent content values for 
diff erent
+      //       ranges. ranges. Hence, support vectors storing 
diff erent values.
+      Type *ElementType = VT->getElementType();
+      int64_t ElementSize = DL.getTypeStoreSize(ElementType).getFixedValue();
+      auto *ConstContent = cast<Constant>(*Content);
+      Type *Int32Ty = Type::getInt32Ty(ElementType->getContext());
+      SmallVector<int64_t> ElementOffsets(Offsets.begin(), Offsets.end());
+
+      for (int i = 0, e = VT->getElementCount().getFixedValue(); i != e; ++i) {
+        Value *ElementContent = ConstantExpr::getExtractElement(
+            ConstContent, ConstantInt::get(Int32Ty, i));
+
+        // Add the element access.
+        Changed = Changed | addAccess(A, {ElementOffsets, ElementSize}, I,
+                                      ElementContent, Kind, ElementType);
+
+        // Advance the offsets for the next element.
+        for (auto &ElementOffset : ElementOffsets)
+          ElementOffset += ElementSize;
+      }
+    }
     return true;
   };
 

diff  --git a/llvm/test/Transforms/Attributor/value-simplify-pointer-info-vec.ll b/llvm/test/Transforms/Attributor/value-simplify-pointer-info-vec.ll
new file mode 100644
index 000000000000..dae6ce9fa661
--- /dev/null
+++ b/llvm/test/Transforms/Attributor/value-simplify-pointer-info-vec.ll
@@ -0,0 +1,63 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=3 -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
+;
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define i32 @vec_write_0() {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define {{[^@]+}}@vec_write_0
+; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    ret i32 0
+;
+  %a = alloca <2 x i32>
+  store <2 x i32> <i32 0, i32 0>, ptr %a
+  %l1 = load i32, ptr %a
+  %g = getelementptr i32, ptr %a, i64 1
+  %l2 = load i32, ptr %g
+  %add = add i32 %l1, %l2
+  ret i32 %add
+}
+
+define i32 @vec_write_1() {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define {{[^@]+}}@vec_write_1
+; CHECK-SAME: () #[[ATTR0]] {
+; CHECK-NEXT:    ret i32 10
+;
+  %a = alloca <2 x i32>
+  store <2 x i32> <i32 5, i32 5>, ptr %a
+  %l1B = load i32, ptr %a
+  %g = getelementptr i32, ptr %a, i64 1
+  %l2B = load i32, ptr %g
+  %add = add i32 %l1B, %l2B
+  ret i32 %add
+}
+
+; TODO: We should support this.
+define i32 @vec_write_2() {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
+; CHECK-LABEL: define {{[^@]+}}@vec_write_2
+; CHECK-SAME: () #[[ATTR0]] {
+; CHECK-NEXT:    [[A:%.*]] = alloca <2 x i32>, align 8
+; CHECK-NEXT:    store <2 x i32> <i32 3, i32 5>, ptr [[A]], align 8
+; CHECK-NEXT:    [[L1:%.*]] = load i32, ptr [[A]], align 8
+; CHECK-NEXT:    [[G:%.*]] = getelementptr i32, ptr [[A]], i64 1
+; CHECK-NEXT:    [[L2:%.*]] = load i32, ptr [[G]], align 4
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[L1]], [[L2]]
+; CHECK-NEXT:    ret i32 [[ADD]]
+;
+  %a = alloca <2 x i32>
+  store <2 x i32> <i32 3, i32 5>, ptr %a
+  %l1 = load i32, ptr %a
+  %g = getelementptr i32, ptr %a, i64 1
+  %l2 = load i32, ptr %g
+  %add = add i32 %l1, %l2
+  ret i32 %add
+}
+;.
+; CHECK: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind willreturn memory(none) }
+;.
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CGSCC: {{.*}}
+; TUNIT: {{.*}}


        


More information about the llvm-commits mailing list