[PATCH] D86396: [Attributor] Change AANoUndef not to deduce noundef for dead returned positions
Shinji Okumura via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 22 05:27:43 PDT 2020
okura created this revision.
Herald added subscribers: llvm-commits, kuter, uenoku, hiraditya.
Herald added a reviewer: uenoku.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: homerdin.
Herald added a project: LLVM.
okura requested review of this revision.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added a subscriber: bbn.
When a returned position is dead, returned values will be replaced with undef values by AAIsDead.
Therefore we should not deduce noundef for the position. Otherwise, AAUndefinedBehavior caught that and replace them with `unreachable` incorrectly.
https://reviews.llvm.org/D86396
Files:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/noundef.ll
Index: llvm/test/Transforms/Attributor/noundef.ll
===================================================================
--- llvm/test/Transforms/Attributor/noundef.ll
+++ llvm/test/Transforms/Attributor/noundef.ll
@@ -20,3 +20,21 @@
call void @bar(i32* %x)
ret void
}
+
+define internal i8* @returned_dead() {
+; CHECK-LABEL: define internal noalias align 536870912 i8* @returned_dead(
+; CHECK-NEXT: call void @unknown()
+; CHECK-NEXT: ret i8* undef
+;
+ call void @unknown()
+ ret i8* null
+}
+
+define void @caller() {
+; CHECK-LABEL: @caller(
+; CHECK-NEXT: [[TMP1:%.*]] = call i8* @returned_dead()
+; CHECK-NEXT: ret void
+;
+ call i8* @returned_dead()
+ ret void
+}
Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -7786,8 +7786,18 @@
struct AANoUndefReturned final
: AAReturnedFromReturnedValues<AANoUndef, AANoUndefImpl> {
- AANoUndefReturned(const IRPosition &IRP, Attributor &A)
- : AAReturnedFromReturnedValues<AANoUndef, AANoUndefImpl>(IRP, A) {}
+ using Base = AAReturnedFromReturnedValues<AANoUndef, AANoUndefImpl>;
+ AANoUndefReturned(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {}
+
+ /// See AbstractAttribute::updateImpl(...).
+ ChangeStatus updateImpl(Attributor &A) override {
+ auto &LivenessAA = A.getAAFor<AAIsDead>(*this, getIRPosition());
+ // When the returned position is dead, returned values will be replaced with
+ // undef values by AAIsDead. So we don't deduce noundef for this position.
+ if (LivenessAA.isKnown())
+ return indicatePessimisticFixpoint();
+ return Base::updateImpl(A);
+ }
/// See AbstractAttribute::trackStatistics()
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noundef) }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86396.287175.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200822/59d86b04/attachment.bin>
More information about the llvm-commits
mailing list