[PATCH] D148706: [FlattenCFG] Add a test to demonstrate bug

Aleksandr Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 04:33:08 PDT 2023


aleksandr.popov created this revision.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

FlattenCFGOpt combines the conditions but doesn't update branch with a
new combined condition. It happens when one of the combinable condition
is inverted and has more then 1 user.


https://reviews.llvm.org/D148706

Files:
  llvm/test/Transforms/Util/flattencfg.ll


Index: llvm/test/Transforms/Util/flattencfg.ll
===================================================================
--- llvm/test/Transforms/Util/flattencfg.ll
+++ llvm/test/Transforms/Util/flattencfg.ll
@@ -232,3 +232,40 @@
   %val_i1_46 = call i1 @llvm.smax.i1(i1 %val_i1_5, i1 %val_i1_5)
   br i1 %val_i1_46, label %bb_4, label %bb_2
 }
+
+; cmp.y has 2 users, but should be inverted. So that a new one cmp is created instead.
+; TODO: Branch condition must be replaced with a new created combined condition
+define i1 @test_cond_multi_use(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: define i1 @test_cond_multi_use
+; CHECK-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[Z:%.*]]) {
+; CHECK-NEXT:  entry.x:
+; CHECK-NEXT:    [[CMP_X:%.*]] = icmp ne i32 [[X]], 0
+; CHECK-NEXT:    [[CMP_Y:%.*]] = icmp eq i32 [[Y]], 0
+; CHECK-NEXT:    [[TMP0:%.*]] = xor i1 [[CMP_Y]], true
+; CHECK-NEXT:    [[TMP1:%.*]] = or i1 [[CMP_X]], [[TMP0]]
+; CHECK-NEXT:    br i1 [[CMP_Y]], label [[IF_THEN_Y:%.*]], label [[EXIT:%.*]]
+; CHECK:       if.then.y:
+; CHECK-NEXT:    store i32 [[Z]], ptr @g, align 4
+; CHECK-NEXT:    br label [[EXIT]]
+; CHECK:       exit:
+; CHECK-NEXT:    ret i1 [[CMP_Y]]
+;
+entry.x:
+  %cmp.x = icmp ne i32 %x, 0
+  br i1 %cmp.x, label %if.then.x, label %entry.y
+
+if.then.x:
+  store i32 %z, ptr @g, align 4
+  br label %entry.y
+
+entry.y:
+  %cmp.y = icmp eq i32 %y, 0
+  br i1 %cmp.y, label %exit, label %if.then.y
+
+if.then.y:
+  store i32 %z, ptr @g, align 4
+  br label %exit
+
+exit:
+  ret i1 %cmp.y
+}
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148706.514900.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230419/4e15f99c/attachment.bin>


More information about the llvm-commits mailing list