[llvm] [PredicateInfo] Support existing `PredicateType` by adding `PredicatePHI` when needing introduction of phi nodes (PR #151132)

Rajveer Singh Bharadwaj via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 19 08:21:18 PDT 2025


================
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=print-predicateinfo < %s 2>&1 >/dev/null | FileCheck %s
+
+ at p = local_unnamed_addr global i32 0
+
+define noundef i32 @h5diff(i32 %0, i1 %1) local_unnamed_addr #0 {
+; CHECK-LABEL: @h5diff(
+; CHECK-NEXT:    [[COND:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
+; CHECK-NEXT:    br i1 [[TMP1:%.*]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    store i32 1, ptr @p, align 4
+; CHECK:         [[DOT0:%.*]] = call i32 @llvm.ssa.copy.i32(i32 [[TMP0]])
+; CHECK-NEXT:    br i1 [[COND]], label [[TMP5:%.*]], label [[COMMON_RET:%.*]]
+; CHECK:       common.ret:
+; CHECK-NEXT:    ret i32 0
+; CHECK:       4:
+; CHECK-NEXT:    store i32 2, ptr @p, align 4
+; CHECK:         [[DOT1:%.*]] = call i32 @llvm.ssa.copy.i32(i32 [[TMP0]])
+; CHECK-NEXT:    br i1 [[COND]], label [[TMP5]], label [[COMMON_RET]]
+; CHECK:       5:
+; CHECK-NEXT:    [[DOTPREDICATE_PHI:%.*]] = phi i32 [ [[DOT1]], [[TMP4]] ], [ [[DOT0]], [[TMP3]] ]
+; CHECK:         [[TMP6:%.*]] = call i32 @llvm.ssa.copy.i32(i32 [[TMP0]])
----------------
Rajveer100 wrote:

It's more of a choice, it might seem a bit overwhelming to see a new predicate which sort of acts as a wrap.

I still think though it's worth it from a future perspective because if something else gets introduced or added it's probably easier to deal with things if this addition is enclosed in a box.

In terms of removal, actually this is also handled here, since we only create these phi nodes when we most definitely know it's needed. It's not considered in the first place otherwise.

https://github.com/llvm/llvm-project/pull/151132


More information about the llvm-commits mailing list