Skip to content

Commit

Permalink
[Attributor] Use changeUseAfterManifest in AAValueSimplify manifest
Browse files Browse the repository at this point in the history
Summary: This patch makes `AAValueSimplify` use `changeUsesAfterManifest` in `manifest`. This will invoke simple folding after the manifest.

Reviewers: jdoerfert, sstefan1

Reviewed By: jdoerfert

Subscribers: hiraditya, arphaman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71972
  • Loading branch information
uenoku committed Dec 30, 2019
1 parent bb87364 commit 34fe8d0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Expand Up @@ -823,6 +823,16 @@ struct Attributor {
return true;
}

/// Helper function to replace all uses of \p V with \p NV. Return true if
/// there is any change.
bool changeValueAfterManifest(Value &V, Value &NV) {
bool Changed = false;
for (auto &U : V.uses())
Changed |= changeUseAfterManifest(U, NV);

return Changed;
}

/// Get pointer operand of memory accessing instruction. If \p I is
/// not a memory accessing instruction, return nullptr. If \p AllowVolatile,
/// is set to false and the instruction is volatile, return nullptr.
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Expand Up @@ -2574,9 +2574,7 @@ struct AAIsDeadFloating : public AAIsDeadValueImpl {
return ChangeStatus::UNCHANGED;

UndefValue &UV = *UndefValue::get(V.getType());
bool AnyChange = false;
for (Use &U : V.uses())
AnyChange |= A.changeUseAfterManifest(U, UV);
bool AnyChange = A.changeValueAfterManifest(V, UV);
return AnyChange ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED;
}

Expand Down Expand Up @@ -4149,7 +4147,7 @@ struct AAValueSimplifyImpl : AAValueSimplify {
if (!V.user_empty() && &V != C && V.getType() == C->getType()) {
LLVM_DEBUG(dbgs() << "[Attributor][ValueSimplify] " << V << " -> " << *C
<< "\n");
replaceAllInstructionUsesWith(V, *C);
A.changeValueAfterManifest(V, *C);
Changed = ChangeStatus::CHANGED;
}
}
Expand Down
Expand Up @@ -9,7 +9,7 @@ define internal i32 @callee(i1 %C, i32* %A) {
; CHECK-SAME: (i1 [[C:%.*]], i32* noalias nocapture nofree nonnull readonly dereferenceable(4) [[A:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_0:%.*]] = load i32, i32* null
; CHECK-NEXT: br i1 false, label [[T:%.*]], label [[F:%.*]]
; CHECK-NEXT: br label [[F:%.*]]
; CHECK: T:
; CHECK-NEXT: unreachable
; CHECK: F:
Expand Down
Expand Up @@ -6,7 +6,7 @@ define internal i32 @callee(i1 %C, i32* %P) {
; CHECK-LABEL: define {{[^@]+}}@callee
; CHECK-SAME: (i1 [[C:%.*]], i32* noalias nocapture nofree readnone [[P:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 true, label [[T:%.*]], label [[F:%.*]]
; CHECK-NEXT: br label [[T:%.*]]
; CHECK: T:
; CHECK-NEXT: ret i32 17
; CHECK: F:
Expand Down
Expand Up @@ -6,11 +6,11 @@ target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:1
define internal i32 @callee(i1 %C, i32* %P) {
; CHECK-LABEL: define {{[^@]+}}@callee
; CHECK-SAME: (i1 [[C:%.*]], i32* noalias nocapture nofree nonnull readonly align 4 dereferenceable(4) [[P:%.*]])
; CHECK-NEXT: br i1 false, label [[T:%.*]], label [[F:%.*]]
; CHECK-NEXT: br label [[F:%.*]]
; CHECK: T:
; CHECK-NEXT: unreachable
; CHECK: F:
; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P]], align 4
; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P:%.*]], align 4
; CHECK-NEXT: ret i32 [[X]]
;
br i1 %C, label %T, label %F
Expand Down
Expand Up @@ -17,7 +17,7 @@ define internal fastcc void @fn(i32* nocapture readonly %p1, i64* nocapture read
; CHECK-LABEL: define {{[^@]+}}@fn
; CHECK-SAME: (i32* nocapture nofree nonnull readonly align 4 dereferenceable(4) [[P1:%.*]], i64* nocapture nofree nonnull readonly align 8 dereferenceable(8) [[P2:%.*]])
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* @c, align 8, !tbaa !0
; CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* undef, align 8, !tbaa !0
; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[TMP0]] to i32
; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* @g, align 4, !tbaa !4
; CHECK-NEXT: [[CONV1:%.*]] = trunc i32 [[TMP1]] to i8
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/Attributor/value-simplify.ll
Expand Up @@ -145,7 +145,7 @@ f:
define internal i1 @ipccp2i(i1 %a) {
; CHECK-LABEL: define {{[^@]+}}@ipccp2i
; CHECK-SAME: (i1 returned [[A:%.*]]) #0
; CHECK-NEXT: br i1 true, label [[T:%.*]], label [[F:%.*]]
; CHECK-NEXT: br label %t
; CHECK: t:
; CHECK-NEXT: ret i1 true
; CHECK: f:
Expand Down

0 comments on commit 34fe8d0

Please sign in to comment.