Skip to content

Commit bf08836

Browse files
Camsyndvbuka
authored andcommitted
[PredicateInfo] Reformat PT_Switch's annotation as valid comments (llvm#165249)
Previously, PredicateInfo brutally annotated `PT_Switch` as follows: ```python f'"; switch predicate info ... CaseValue: ... Switch: {*PS->Switch} Edge: ... RenamedOp: ..."' ``` However, the `switch` instruction in LLVM might cross >1 lines, leading to the annotation of `PT_Switch` being **illegal comments**, e.g., ```LLVM ; switch predicate info { CaseValue: i32 1 Switch: switch i32 %x, label %default [ i32 0, label %case0 i32 1, label %case1 i32 2, label %case0 i32 3, label %case3 i32 4, label %default ] Edge: [label %sw,label %case1], RenamedOp: %x } x.0 = bitcast i32 %x to i32 ``` This patch removes the `switch` printing, reformating the `PT_Switch`'s annotation as follows: ```python f'"; switch predicate info ... CaseValue: ... Edge: ... RenamedOp: ..."' ``` , e.g., ```LLVM ; switch predicate info { CaseValue: i32 1 Edge: [label %sw,label %case1], RenamedOp: %x } x.0 = bitcast i32 %x to i32 ``` It should be Okay because `CaseValue: ...` + `Edge: ...` are meaningful enough for diagnostics, covering the necessary info provided by full switch printing (E.g., `PT_Branch` also did not print the relevant branch instruction).
1 parent a87608a commit bf08836

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

llvm/lib/Transforms/Utils/PredicateInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ class PredicateInfoAnnotatedWriter : public AssemblyAnnotationWriter {
819819
OS << "]";
820820
} else if (const auto *PS = dyn_cast<PredicateSwitch>(PI)) {
821821
OS << "; switch predicate info { CaseValue: " << *PS->CaseValue
822-
<< " Switch:" << *PS->Switch << " Edge: [";
822+
<< " Edge: [";
823823
PS->From->printAsOperand(OS);
824824
OS << ",";
825825
PS->To->printAsOperand(OS);

llvm/test/Transforms/Util/PredicateInfo/condprop.ll

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,13 @@ define void @test4(i1 %b, i32 %x) {
133133
; CHECK-LABEL: @test4(
134134
; CHECK-NEXT: br i1 [[B:%.*]], label [[SW:%.*]], label [[CASE3:%.*]]
135135
; CHECK: sw:
136-
; CHECK: i32 0, label [[CASE0:%.*]]
137-
; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
138-
; CHECK-NEXT: i32 2, label [[CASE0]]
139-
; CHECK-NEXT: i32 3, label [[CASE3]]
140-
; CHECK-NEXT: i32 4, label [[DEFAULT:%.*]]
141-
; CHECK-NEXT: ] Edge: [label [[SW]],label %case1], RenamedOp: [[X:%.*]] }
142-
; CHECK-NEXT: [[X_0:%.*]] = bitcast i32 [[X]] to i32
143-
; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT]] [
144-
; CHECK-NEXT: i32 0, label [[CASE0]]
145-
; CHECK-NEXT: i32 1, label [[CASE1]]
146-
; CHECK-NEXT: i32 2, label [[CASE0]]
147-
; CHECK-NEXT: i32 3, label [[CASE3]]
148-
; CHECK-NEXT: i32 4, label [[DEFAULT]]
136+
; CHECK: [[X_0:%.*]] = bitcast i32 [[X:%.*]] to i32
137+
; CHECK-NEXT: switch i32 [[X]], label [[DEFAULT:%.*]] [
138+
; CHECK-NEXT: i32 0, label [[CASE0:%.*]]
139+
; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
140+
; CHECK-NEXT: i32 2, label [[CASE0]]
141+
; CHECK-NEXT: i32 3, label [[CASE3]]
142+
; CHECK-NEXT: i32 4, label [[DEFAULT]]
149143
; CHECK-NEXT: ]
150144
; CHECK: default:
151145
; CHECK-NEXT: call void @bar(i32 [[X]])

0 commit comments

Comments
 (0)