[llvm] 2f7ef7b - [Attributor][FIX] Swap cases in ternary op to avoid nullptr reference
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 00:05:11 PDT 2023
Author: Johannes Doerfert
Date: 2023-07-26T00:03:06-07:00
New Revision: 2f7ef7be1f5173c604150f4dd6ada04920ef11a8
URL: https://github.com/llvm/llvm-project/commit/2f7ef7be1f5173c604150f4dd6ada04920ef11a8
DIFF: https://github.com/llvm/llvm-project/commit/2f7ef7be1f5173c604150f4dd6ada04920ef11a8.diff
LOG: [Attributor][FIX] Swap cases in ternary op to avoid nullptr reference
The case was wrong before, and somehow I only looked at the condition
before.
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/Attributor/reduced/openmp_opt_constant_type_crash.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 73198127f445c6..fe82506d0e4a42 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1979,8 +1979,8 @@ bool Attributor::checkForAllInstructions(function_ref<bool(Instruction &)> Pred,
const IRPosition &QueryIRP = IRPosition::function(*Fn);
const auto *LivenessAA =
CheckPotentiallyDead && QueryingAA
- ? nullptr
- : (getAAFor<AAIsDead>(*QueryingAA, QueryIRP, DepClassTy::NONE));
+ ? (getAAFor<AAIsDead>(*QueryingAA, QueryIRP, DepClassTy::NONE))
+ : nullptr;
auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(*Fn);
if (!checkForAllInstructionsImpl(this, OpcodeInstMap, Pred, QueryingAA,
diff --git a/llvm/test/Transforms/Attributor/reduced/openmp_opt_constant_type_crash.ll b/llvm/test/Transforms/Attributor/reduced/openmp_opt_constant_type_crash.ll
index 5cf2ac9e768c87..fda72a6e31a0c7 100644
--- a/llvm/test/Transforms/Attributor/reduced/openmp_opt_constant_type_crash.ll
+++ b/llvm/test/Transforms/Attributor/reduced/openmp_opt_constant_type_crash.ll
@@ -70,12 +70,13 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret void
;
;
-; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl11ViewMappingIvJNS_10ViewTraitsIPPdJNS_11LayoutRightENS_18ScratchMemorySpaceINS_12Experimental12OpenMPTargetEEENS_12MemoryTraitsILj1EEEEEENS0_5ALL_tEiEE6assignINS2_IS3_JNS_12LayoutStrideENS_6DeviceIS8_S9_EESB_EEEEEvRNS1_IT_JvEEERKNS1_ISC_JvEEESD_i.internalized() {
+; CHECK: Function Attrs: norecurse
+; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl11ViewMappingIvJNS_10ViewTraitsIPPdJNS_11LayoutRightENS_18ScratchMemorySpaceINS_12Experimental12OpenMPTargetEEENS_12MemoryTraitsILj1EEEEEENS0_5ALL_tEiEE6assignINS2_IS3_JNS_12LayoutStrideENS_6DeviceIS8_S9_EESB_EEEEEvRNS1_IT_JvEEERKNS1_ISC_JvEEESD_i.internalized
+; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[EXTENTS11:%.*]] = alloca [0 x [0 x %"struct.Kokkos::Impl::SubviewExtents.448"]], i32 0, align 8, addrspace(5)
; CHECK-NEXT: [[EXTENTS_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[EXTENTS11]] to ptr
; CHECK-NEXT: call void @_ZN6Kokkos4Impl14SubviewExtentsILj2ELj1EEC2IJLm0ELm0EEJNS0_5ALL_tEiEEERKNS0_13ViewDimensionIJXspT_EEEEDpT0_.internalized(ptr [[EXTENTS_ASCAST]])
-; CHECK-NEXT: call void @_ZN6Kokkos4Impl10ViewOffsetINS0_13ViewDimensionIJLm0EEEENS_12LayoutStrideEvEC2INS2_IJLm0ELm0EEEENS_11LayoutRightEEERKNS1_IT_T0_vEERKNS0_14SubviewExtentsIXsrS9_4rankELj1EEE.internalized(ptr [[EXTENTS_ASCAST]])
; CHECK-NEXT: ret void
;
;
@@ -88,10 +89,11 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret void
;
;
+; CHECK: Function Attrs: norecurse nosync nounwind memory(argmem: write)
; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl14SubviewExtentsILj2ELj1EEC2IJLm0ELm0EEJNS0_5ALL_tEiEEERKNS0_13ViewDimensionIJXspT_EEEEDpT0_.internalized
-; CHECK-SAME: (ptr [[THIS:%.*]]) {
+; CHECK-SAME: (ptr [[THIS:%.*]]) #[[ATTR1:[0-9]+]] {
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[CALL:%.*]] = call i1 @_ZN6Kokkos4Impl14SubviewExtentsILj2ELj1EE3setIJLm0ELm0EEJiEEEbjjRKNS0_13ViewDimensionIJXspT_EEEENS0_5ALL_tEDpT0_.internalized(ptr [[THIS]])
+; CHECK-NEXT: [[CALL:%.*]] = call i1 @_ZN6Kokkos4Impl14SubviewExtentsILj2ELj1EE3setIJLm0ELm0EEJiEEEbjjRKNS0_13ViewDimensionIJXspT_EEEENS0_5ALL_tEDpT0_.internalized(ptr writeonly [[THIS]])
; CHECK-NEXT: ret void
;
;
@@ -102,14 +104,6 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret void
;
;
-; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl10ViewOffsetINS0_13ViewDimensionIJLm0EEEENS_12LayoutStrideEvEC2INS2_IJLm0ELm0EEEENS_11LayoutRightEEERKNS1_IT_T0_vEERKNS0_14SubviewExtentsIXsrS9_4rankELj1EEE.internalized
-; CHECK-SAME: (ptr [[SUB:%.*]]) {
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[CALL191:%.*]] = call i32 @_ZNK6Kokkos4Impl14SubviewExtentsILj2ELj1EE11range_indexIiEEjT_.internalized(ptr [[SUB]])
-; CHECK-NEXT: [[CALL201:%.*]] = call i64 @_ZN6Kokkos4Impl10ViewOffsetINS0_13ViewDimensionIJLm0EEEENS_12LayoutStrideEvE6strideINS2_IJLm0ELm0EEEENS_11LayoutRightEEEmjRKNS1_IT_T0_vEE.internalized(i32 [[CALL191]])
-; CHECK-NEXT: ret void
-;
-;
; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl10ViewOffsetINS0_13ViewDimensionIJLm0EEEENS_12LayoutStrideEvEC2INS2_IJLm0ELm0EEEENS_11LayoutRightEEERKNS1_IT_T0_vEERKNS0_14SubviewExtentsIXsrS9_4rankELj1EEE
; CHECK-SAME: (ptr [[SUB:%.*]]) {
; CHECK-NEXT: entry:
@@ -118,10 +112,10 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret void
;
;
+; CHECK: Function Attrs: norecurse nosync nounwind memory(argmem: write)
; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl14SubviewExtentsILj2ELj1EE3setIJLm0ELm0EEJiEEEbjjRKNS0_13ViewDimensionIJXspT_EEEENS0_5ALL_tEDpT0_.internalized
-; CHECK-SAME: (ptr [[THIS:%.*]]) {
+; CHECK-SAME: (ptr nocapture writeonly [[THIS:%.*]]) #[[ATTR1]] {
; CHECK-NEXT: entry:
-; CHECK-NEXT: store i64 0, ptr [[THIS]], align 8
; CHECK-NEXT: ret i1 false
;
;
@@ -132,13 +126,6 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret i1 false
;
;
-; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl10ViewOffsetINS0_13ViewDimensionIJLm0EEEENS_12LayoutStrideEvE6strideINS2_IJLm0ELm0EEEENS_11LayoutRightEEEmjRKNS1_IT_T0_vEE.internalized
-; CHECK-SAME: (i32 [[R:%.*]]) {
-; CHECK-NEXT: entry:
-; CHECK-NEXT: store i32 [[R]], ptr null, align 4294967296
-; CHECK-NEXT: ret i64 0
-;
-;
; CHECK-LABEL: define {{[^@]+}}@_ZN6Kokkos4Impl10ViewOffsetINS0_13ViewDimensionIJLm0EEEENS_12LayoutStrideEvE6strideINS2_IJLm0ELm0EEEENS_11LayoutRightEEEmjRKNS1_IT_T0_vEE
; CHECK-SAME: (i32 [[R:%.*]]) {
; CHECK-NEXT: entry:
@@ -146,19 +133,6 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret i64 0
;
;
-; CHECK-LABEL: define {{[^@]+}}@_ZNK6Kokkos4Impl14SubviewExtentsILj2ELj1EE11range_indexIiEEjT_.internalized
-; CHECK-SAME: (ptr [[THIS:%.*]]) {
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 1, 0
-; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
-; CHECK: cond.true:
-; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[THIS]], align 4
-; CHECK-NEXT: br label [[COND_END]]
-; CHECK: cond.end:
-; CHECK-NEXT: [[COND:%.*]] = phi i32 [ [[TMP0]], [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ]
-; CHECK-NEXT: ret i32 [[COND]]
-;
-;
; CHECK-LABEL: define {{[^@]+}}@_ZNK6Kokkos4Impl14SubviewExtentsILj2ELj1EE11range_indexIiEEjT_
; CHECK-SAME: (ptr [[THIS:%.*]]) {
; CHECK-NEXT: entry:
@@ -172,6 +146,10 @@ cond.end: ; preds = %cond.true, %entry
; CHECK-NEXT: ret i32 [[COND]]
;
;.
+; CHECK: attributes #[[ATTR0]] = { norecurse }
+; CHECK: attributes #[[ATTR1]] = { norecurse nosync nounwind memory(argmem: write) }
+; CHECK: attributes #[[ATTR2:[0-9]+]] = { nosync nounwind memory(write) }
+;.
; 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