[llvm] [JumpThreading] Thread over BB with only an unconditional branch (PR #86312)
Quentin Dian via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 23 04:04:39 PDT 2024
================
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt < %s -passes=simplifycfg,instcombine -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
+
+; Add InstCombine pass to demonstrate the effect of threading
+
+define i32 @thread_uncond_bb_cmp(i1 %c, i32 %v) {
+; CHECK-LABEL: define i32 @thread_uncond_bb_cmp(
+; CHECK-SAME: i1 [[C:%.*]], i32 [[V:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[C]], label [[DO_END:%.*]], label [[IF_THEN:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: call void @dummy()
+; CHECK-NEXT: br label [[DO_END]]
+; CHECK: return:
+; CHECK-NEXT: [[RETVAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[V]], [[IF_THEN]] ]
+; CHECK-NEXT: ret i32 [[RETVAL]]
+;
+entry:
+ br i1 %c, label %do.end, label %if.then
+
+if.then: ; preds = %entry
+ call void @dummy()
+ %tobool = icmp eq i32 %v, 0
+ br i1 %tobool, label %do.end, label %return
+
+do.end: ; preds = %entry, %if.then
+ br label %return
+
+return: ; preds = %if.then, %do.end
+ %retval = phi i32 [ 0, %do.end ], [ %v, %if.then ]
+ ret i32 %retval
+}
+
+define i32 @thread_uncond_bb_cmp_zext(i1 %c, i32 %v) {
----------------
DianQK wrote:
> I think that the phase-ordering tests emphasize the impact after changing pipeline. I don't have a strong opinion on this, update it if you're more happy with PhaseOrdering.
IIUC, we often put test cases that require multiple passes here. :)
> I add two similar testcases because they are found in the benchmark frequently. And the icmp of one of them is not optimized away, it could be seen as not-that-optimal one.
IIUC, this cannot be optimized.
https://github.com/llvm/llvm-project/pull/86312
More information about the llvm-commits
mailing list