From: Johannes Doerfert Date: Thu, 22 Dec 2022 01:03:35 +0000 (-0800) Subject: [Attributor][FIX] Treat undef as zero offset in AAPointerInfoFloating X-Git-Tag: upstream/17.0.6~22245 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b0cee1f4ba50f1140dfb2bd501e0d061c609f2ef;p=platform%2Fupstream%2Fllvm.git [Attributor][FIX] Treat undef as zero offset in AAPointerInfoFloating --- diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 6cf666f..533afe4 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 0000000..682aaf6 --- /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} +;.