[llvm] b0cee1f - [Attributor][FIX] Treat undef as zero offset in AAPointerInfoFloating

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 13:10:02 PST 2023


Author: Johannes Doerfert
Date: 2023-01-03T13:09:23-08:00
New Revision: b0cee1f4ba50f1140dfb2bd501e0d061c609f2ef

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

LOG: [Attributor][FIX] Treat undef as zero offset in AAPointerInfoFloating

Added: 
    llvm/test/Transforms/Attributor/reduced/openmp_opt_dont_follow_gep_without_value.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 6cf666ffe6b82..533afe4fa17c2 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1400,15 +1400,16 @@ bool AAPointerInfoFloating::collectConstantsForGEP(Attributor &A,
       return true;
     }
 
-    auto &AssumedSet = PotentialConstantsAA.getAssumedSet();
+    // UndefValue is treated as a zero, which leaves Union as is.
+    if (PotentialConstantsAA.undefIsContained())
+      continue;
 
     // We need at least one constant in every set to compute an actual offset.
     // Otherwise, we end up pessimizing AAPointerInfo by respecting offsets that
     // don't actually exist. In other words, the absence of constant values
     // implies that the operation can be assumed dead for now.
-    //
-    // UndefValue is treated as a zero.
-    if (!PotentialConstantsAA.undefIsContained() && AssumedSet.empty())
+    auto &AssumedSet = PotentialConstantsAA.getAssumedSet();
+    if (AssumedSet.empty())
       return false;
 
     OffsetInfo Product;

diff  --git a/llvm/test/Transforms/Attributor/reduced/openmp_opt_dont_follow_gep_without_value.ll b/llvm/test/Transforms/Attributor/reduced/openmp_opt_dont_follow_gep_without_value.ll
new file mode 100644
index 0000000000000..682aaf66cfd69
--- /dev/null
+++ b/llvm/test/Transforms/Attributor/reduced/openmp_opt_dont_follow_gep_without_value.ll
@@ -0,0 +1,59 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --check-attributes --check-globals --include-generated-funcs
+; RUN: opt -aa-pipeline=basic-aa -passes=openmp-opt -S < %s | FileCheck %s --check-prefixes=CHECK
+
+define void @f() {
+  %1 = alloca i64
+  %2 = call double @g(ptr %1)
+  ret void
+}
+
+define internal double @g(ptr %0) {
+  %2 = call ptr @h(ptr %0)
+  ret double 0.000000e+00
+}
+
+define weak_odr ptr @h(ptr %0) {
+  %2 = load i64, ptr %0
+  %3 = getelementptr double, ptr %0, i64 %2
+  ret ptr %3
+}
+
+!llvm.module.flags = !{!0, !1}
+
+!0 = !{i32 7, !"openmp", i32 50}
+!1 = !{i32 7, !"openmp-device", i32 50}
+; CHECK: Function Attrs: norecurse
+; CHECK-LABEL: define {{[^@]+}}@f
+; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = alloca i64, align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = call double @g(ptr [[TMP1]])
+; CHECK-NEXT:    ret void
+;
+;
+; CHECK: Function Attrs: norecurse
+; CHECK-LABEL: define {{[^@]+}}@g
+; CHECK-SAME: (ptr [[TMP0:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[TMP2:%.*]] = call ptr @h.internalized(ptr [[TMP0]])
+; CHECK-NEXT:    ret double 0.000000e+00
+;
+;
+; CHECK: Function Attrs: norecurse nosync
+; CHECK-LABEL: define {{[^@]+}}@h.internalized
+; CHECK-SAME: (ptr [[TMP0:%.*]]) #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr double, ptr [[TMP0]], i64 undef
+; CHECK-NEXT:    ret ptr [[TMP2]]
+;
+;
+; CHECK-LABEL: define {{[^@]+}}@h
+; CHECK-SAME: (ptr [[TMP0:%.*]]) {
+; CHECK-NEXT:    [[TMP2:%.*]] = load i64, ptr [[TMP0]], align 4
+; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr double, ptr [[TMP0]], i64 [[TMP2]]
+; CHECK-NEXT:    ret ptr [[TMP3]]
+;
+;.
+; CHECK: attributes #[[ATTR0]] = { norecurse }
+; CHECK: attributes #[[ATTR1]] = { norecurse nosync }
+;.
+; CHECK: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
+; CHECK: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
+;.


        


More information about the llvm-commits mailing list