[llvm] [SimplifyCFG] Add test for merging branches with different !annotation metadata (PR #88728)

Julian Nagele via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 06:05:54 PDT 2024


https://github.com/juliannagele created https://github.com/llvm/llvm-project/pull/88728

This test exposes what I believe is incorrect behaviour when merging two branches that have different `!annotation` metadata. Currently, the remaining branch in the entry block does not get the annotation of the other branch, thus not properly representing the fact that it is a merge of both. Similarly, the created select should get both annotations, since it also represents a merge of the two branches.

>From 65d1dad45e1fd12a845d4e7f0f03382a257f4b08 Mon Sep 17 00:00:00 2001
From: Julian Nagele <j.nagele at apple.com>
Date: Mon, 15 Apr 2024 11:13:48 +0100
Subject: [PATCH] [SimplifyFCG] Add test for merging branches with different
 !annotation metadata

This test shows the behaviour when merging two branches that have
different !annotation metadata.
---
 .../Transforms/SimplifyCFG/annotations.ll     | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/llvm/test/Transforms/SimplifyCFG/annotations.ll b/llvm/test/Transforms/SimplifyCFG/annotations.ll
index 9a9aca05629f98..956c77e94befbe 100644
--- a/llvm/test/Transforms/SimplifyCFG/annotations.ll
+++ b/llvm/test/Transforms/SimplifyCFG/annotations.ll
@@ -139,7 +139,45 @@ cont1:                                            ; preds = %cont
   ret i32 0
 }
 
+;; The branches in entry and cont have different !annotation metadata. Make sure
+;; the annotations are merged in the OR and the remaning branch.
+;; FIXME: Currently, the resulting branch in the entry block does not get the !1
+;; annotation (because it is not newly created).  Similarly, the OR does get the
+;; !1 annotation, but not the !0 annotation; since it also represents a merge of
+;; the two branches it should have both.
+define i32 @test_merge_annotations(ptr %a, ptr %b, ptr %c, ptr %d) {
+; CHECK-LABEL: define i32 @test_merge_annotations({{.*}}
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[A:%.*]], [[B:%.*]], !annotation !0
+; CHECK-NEXT:    [[C_2:%.*]] = icmp uge ptr [[C:%.*]], [[D:%.*]], !annotation !1
+; CHECK-NEXT:    [[OR_COND:%.*]] = select i1 [[C_1]], i1 [[C_2]], i1 false, !annotation !1
+; CHECK-NEXT:    br i1 [[OR_COND]], label [[CONT1:%.*]], label [[TRAP:%.*]], !annotation !0
+; CHECK:       trap: ; preds = %entry
+; CHECK-NEXT:    call void @fn1()
+; CHECK-NEXT:    unreachable
+; CHECK:       cont1:  ; preds = %entry
+; CHECK-NEXT:    call void @fn2()
+; CHECK-NEXT:    ret i32 0
+;
+entry:
+  %c.1 = icmp ult ptr %a, %b, !annotation !0
+  br i1 %c.1, label %cont, label %trap, !annotation !0
+
+cont:                                             ; preds = %entry
+  %c.2 = icmp uge ptr %c, %d, !annotation !1
+  br i1 %c.2, label %cont1, label %trap, !annotation !1
+
+trap:                                             ; preds = %cont, %entry
+  call void @fn1()
+  unreachable
+
+cont1:                                            ; preds = %cont
+  call void @fn2()
+  ret i32 0
+}
+
 declare void @fn1()
 declare void @fn2()
 
 !0 = !{!"foo"}
+!1 = !{!"foo1"}



More information about the llvm-commits mailing list