Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions llvm/lib/IR/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,17 @@ void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
}

void Instruction::dropUBImplyingAttrsAndMetadata(ArrayRef<unsigned> Keep) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Keep is no longer needed now, but I guess it doesn't hurt to keep it...

// !annotation metadata does not impact semantics.
// !annotation and !prof metadata does not impact semantics.
// !range, !nonnull and !align produce poison, so they are safe to speculate.
// !noundef and various AA metadata must be dropped, as it generally produces
// immediate undefined behavior.
static const unsigned KnownIDs[] = {
LLVMContext::MD_annotation, LLVMContext::MD_range,
LLVMContext::MD_nonnull, LLVMContext::MD_align};
LLVMContext::MD_nonnull, LLVMContext::MD_align, LLVMContext::MD_prof};
SmallVector<unsigned> KeepIDs;
KeepIDs.reserve(Keep.size() + std::size(KnownIDs));
append_range(KeepIDs, KnownIDs);
append_range(KeepIDs, (!ProfcheckDisableMetadataFixes ? KnownIDs
: drop_end(KnownIDs)));
append_range(KeepIDs, Keep);
dropUBImplyingAttrsAndUnknownMetadata(KeepIDs);
}
Expand Down
5 changes: 1 addition & 4 deletions llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,10 +1705,7 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
// time in isGuaranteedToExecute if we don't actually have anything to
// drop. It is a compile time optimization, not required for correctness.
!SafetyInfo->isGuaranteedToExecute(I, DT, CurLoop)) {
if (ProfcheckDisableMetadataFixes)
I.dropUBImplyingAttrsAndMetadata();
else
I.dropUBImplyingAttrsAndMetadata({LLVMContext::MD_prof});
I.dropUBImplyingAttrsAndMetadata();
}

if (isa<PHINode>(I))
Expand Down
21 changes: 14 additions & 7 deletions llvm/test/Transforms/SimplifyCFG/PhiBlockMerge.ll
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
; NOTE: Assertions have been autogenerated by update_test_checks.py
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need the --check-globals, just the new version is enough.

; Test merging of blocks that only have PHI nodes in them
;
; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
;

define i32 @test(i1 %a, i1 %b) {
; CHECK-LABEL: @test(
; CHECK: M:
; CHECK-NEXT: [[DOT:%.*]] = select i1 %b, i32 0, i32 1
; CHECK-NEXT: [[W:%.*]] = select i1 %a, i32 2, i32 [[DOT]]
; CHECK-LABEL: define i32 @test(
; CHECK-SAME: i1 [[A:%.*]], i1 [[B:%.*]]) {
; CHECK-NEXT: [[M:.*:]]
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[B]], i32 0, i32 1, !prof [[PROF0:![0-9]+]]
; CHECK-NEXT: [[W:%.*]] = select i1 [[A]], i32 2, i32 [[SPEC_SELECT]], !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: [[R:%.*]] = add i32 [[W]], 1
; CHECK-NEXT: ret i32 [[R]]
;
br i1 %a, label %M, label %O
br i1 %a, label %M, label %O, !prof !0
O: ; preds = %0
br i1 %b, label %N, label %Q
br i1 %b, label %N, label %Q, !prof !1
Q: ; preds = %O
br label %N
N: ; preds = %Q, %O
Expand All @@ -27,3 +28,9 @@ M: ; preds = %N, %0
ret i32 %R
}

!0 = !{!"branch_weights", i32 11, i32 7}
!1 = !{!"branch_weights", i32 3, i32 5}
;.
; CHECK: [[PROF0]] = !{!"branch_weights", i32 3, i32 5}
; CHECK: [[PROF1]] = !{!"branch_weights", i32 11, i32 7}
;.
Loading