[llvm] b046ebd - [Attributor][FIX] Conservatively handle ptr2int, don't crash
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 11 20:17:14 PDT 2022
Author: Johannes Doerfert
Date: 2022-09-11T20:16:11-07:00
New Revision: b046ebdc01913668361009b2fc259302d2329f29
URL: https://github.com/llvm/llvm-project/commit/b046ebdc01913668361009b2fc259302d2329f29
DIFF: https://github.com/llvm/llvm-project/commit/b046ebdc01913668361009b2fc259302d2329f29.diff
LOG: [Attributor][FIX] Conservatively handle ptr2int, don't crash
If a pointer-2-int cast is found we give up on AAPointerInfo for now.
This caused a crash before.
Reported by John Tramm (@jtramm).
Added:
llvm/test/Transforms/Attributor/reduced/crash_ptr2int_cgscc.ll
Modified:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/OpenMP/parallel_region_merging.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index bc19afb041989..f4c6773da639c 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1292,6 +1292,8 @@ struct AAPointerInfoFloating : public AAPointerInfoImpl {
Follow = true;
return true;
}
+ if (isa<PtrToIntInst>(Usr))
+ return false;
if (isa<CastInst>(Usr) || isa<SelectInst>(Usr) || isa<ReturnInst>(Usr))
return HandlePassthroughUser(Usr, OffsetInfoMap[CurPtr], Follow);
diff --git a/llvm/test/Transforms/Attributor/reduced/crash_ptr2int_cgscc.ll b/llvm/test/Transforms/Attributor/reduced/crash_ptr2int_cgscc.ll
new file mode 100644
index 0000000000000..06e3309838435
--- /dev/null
+++ b/llvm/test/Transforms/Attributor/reduced/crash_ptr2int_cgscc.ll
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --check-attributes --check-globals
+; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM
+; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM
+; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM
+
+define void @_ZN6openmc13FilterBinIterC1ERKNS_5TallyERNS_8ParticleE(i1 %c1, i1 %c2) {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind
+; CHECK-LABEL: define {{[^@]+}}@_ZN6openmc13FilterBinIterC1ERKNS_5TallyERNS_8ParticleE
+; CHECK-SAME: (i1 [[C1:%.*]], i1 [[C2:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[D_I_I_I_I:%.*]] = alloca [3 x double], align 8
+; CHECK-NEXT: br i1 [[C1]], label [[FOR_BODY_LR_PH_I:%.*]], label [[_ZN6OPENMC13FILTERBINITERC2ERKNS_5TALLYERNS_8PARTICLEE_INTERNALIZED_EXIT:%.*]]
+; CHECK: for.body.lr.ph.i:
+; CHECK-NEXT: [[PHI_CAST_I_I_I_I:%.*]] = ptrtoint ptr [[D_I_I_I_I]] to i64
+; CHECK-NEXT: br label [[FOR_BODY_I:%.*]]
+; CHECK: for.body.i:
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr inttoptr (i64 4 to ptr), align 4
+; CHECK-NEXT: [[CMP1_NOT_PEEL_I_I_I_I_I_I:%.*]] = icmp eq i32 [[TMP0]], 1
+; CHECK-NEXT: br i1 [[CMP1_NOT_PEEL_I_I_I_I_I_I]], label [[_ZNK6OPENMC6FILTER12GET_ALL_BINSERKNS_8PARTICLEENS_14TALLYESTIMATORERNS_11FILTERMATCHE_INTERNALIZED_EXIT_I:%.*]], label [[WHILE_COND_PEEL_NEXT_I_I_I_I_I_I:%.*]]
+; CHECK: while.cond.peel.next.i.i.i.i.i.i:
+; CHECK-NEXT: br label [[_ZNK6OPENMC6FILTER12GET_ALL_BINSERKNS_8PARTICLEENS_14TALLYESTIMATORERNS_11FILTERMATCHE_INTERNALIZED_EXIT_I]]
+; CHECK: _ZNK6openmc6Filter12get_all_binsERKNS_8ParticleENS_14TallyEstimatorERNS_11FilterMatchE.internalized.exit.i:
+; CHECK-NEXT: [[DOTLCSSA_I_I_I_I_I_I:%.*]] = phi i64 [ 0, [[FOR_BODY_I]] ], [ [[PHI_CAST_I_I_I_I]], [[WHILE_COND_PEEL_NEXT_I_I_I_I_I_I]] ]
+; CHECK-NEXT: store ptr null, ptr [[D_I_I_I_I]], align 8
+; CHECK-NEXT: [[ARRAYIDX92_I_I_I_I:%.*]] = getelementptr inbounds [3 x double], ptr [[D_I_I_I_I]], i64 0, i64 [[DOTLCSSA_I_I_I_I_I_I]]
+; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[ARRAYIDX92_I_I_I_I]], align 8
+; CHECK-NEXT: store double [[TMP1]], ptr inttoptr (i64 16 to ptr), align 16
+; CHECK-NEXT: br i1 [[C2]], label [[FOR_BODY_I]], label [[_ZN6OPENMC13FILTERBINITERC2ERKNS_5TALLYERNS_8PARTICLEE_INTERNALIZED_EXIT]]
+; CHECK: _ZN6openmc13FilterBinIterC2ERKNS_5TallyERNS_8ParticleE.internalized.exit:
+; CHECK-NEXT: ret void
+;
+entry:
+ %d.i.i.i.i = alloca [3 x double], align 8
+ br i1 %c1, label %for.body.lr.ph.i, label %_ZN6openmc13FilterBinIterC2ERKNS_5TallyERNS_8ParticleE.internalized.exit
+
+for.body.lr.ph.i: ; preds = %entry
+ %phi.cast.i.i.i.i = ptrtoint ptr %d.i.i.i.i to i64
+ br label %for.body.i
+
+for.body.i:
+ %0 = load i32, ptr inttoptr (i64 4 to ptr), align 4
+ %idx.ext87.i.i.i.i = sext i32 %0 to i64
+ %add.ptr88.i.i.i.i = getelementptr inbounds double, ptr %d.i.i.i.i, i64 %idx.ext87.i.i.i.i
+ %cmp1.not.peel.i.i.i.i.i.i = icmp eq i32 %0, 1
+ br i1 %cmp1.not.peel.i.i.i.i.i.i, label %_ZNK6openmc6Filter12get_all_binsERKNS_8ParticleENS_14TallyEstimatorERNS_11FilterMatchE.internalized.exit.i, label %while.cond.peel.next.i.i.i.i.i.i
+
+while.cond.peel.next.i.i.i.i.i.i: ; preds = %for.body.i
+ br label %_ZNK6openmc6Filter12get_all_binsERKNS_8ParticleENS_14TallyEstimatorERNS_11FilterMatchE.internalized.exit.i
+
+_ZNK6openmc6Filter12get_all_binsERKNS_8ParticleENS_14TallyEstimatorERNS_11FilterMatchE.internalized.exit.i: ; preds = %while.cond.peel.next.i.i.i.i.i.i, %for.body.i
+ %.lcssa.i.i.i.i.i.i = phi i64 [ 0, %for.body.i ], [ %phi.cast.i.i.i.i, %while.cond.peel.next.i.i.i.i.i.i ]
+ store ptr null, ptr %d.i.i.i.i, align 8
+ %arrayidx92.i.i.i.i = getelementptr inbounds [3 x double], ptr %d.i.i.i.i, i64 0, i64 %.lcssa.i.i.i.i.i.i
+ %1 = load double, ptr %arrayidx92.i.i.i.i, align 8
+ store double %1, ptr inttoptr (i64 16 to ptr), align 16
+ br i1 %c2, label %for.body.i, label %_ZN6openmc13FilterBinIterC2ERKNS_5TallyERNS_8ParticleE.internalized.exit
+
+_ZN6openmc13FilterBinIterC2ERKNS_5TallyERNS_8ParticleE.internalized.exit:
+ ret void
+}
+;.
+; CHECK: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind }
+;.
diff --git a/llvm/test/Transforms/OpenMP/parallel_region_merging.ll b/llvm/test/Transforms/OpenMP/parallel_region_merging.ll
index 7a7a5c7c1a83b..587117be0613b 100644
--- a/llvm/test/Transforms/OpenMP/parallel_region_merging.ll
+++ b/llvm/test/Transforms/OpenMP/parallel_region_merging.ll
@@ -5181,6 +5181,7 @@ entry:
; CHECK1-NEXT: call void @llvm.lifetime.start.p0i8(i64 noundef 4, i8* noundef nonnull [[TMP4]])
; CHECK1-NEXT: [[TMP5:%.*]] = ptrtoint i32* [[B]] to i64
; CHECK1-NEXT: [[TMP6:%.*]] = trunc i64 [[TMP5]] to i32
+; CHECK1-NEXT: store i32 [[TMP6]], i32* [[B]], align 4
; CHECK1-NEXT: call void @llvm.lifetime.end.p0i8(i64 noundef 4, i8* noundef nonnull [[TMP4]])
; CHECK1-NEXT: br label [[OMP_PAR_MERGED_SPLIT:%.*]]
; CHECK1: omp.par.merged.split:
@@ -6396,6 +6397,7 @@ entry:
; CHECK2-NEXT: call void @llvm.lifetime.start.p0i8(i64 noundef 4, i8* noundef nonnull [[TMP4]])
; CHECK2-NEXT: [[TMP5:%.*]] = ptrtoint i32* [[B]] to i64
; CHECK2-NEXT: [[TMP6:%.*]] = trunc i64 [[TMP5]] to i32
+; CHECK2-NEXT: store i32 [[TMP6]], i32* [[B]], align 4
; CHECK2-NEXT: call void @llvm.lifetime.end.p0i8(i64 noundef 4, i8* noundef nonnull [[TMP4]])
; CHECK2-NEXT: br label [[OMP_PAR_MERGED_SPLIT:%.*]]
; CHECK2: omp.par.merged.split:
More information about the llvm-commits
mailing list