[llvm] [ValueTracking] Look through intermediate PHIs for conditional recurrences (PR #215913)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 15:52:07 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: AZero13 (AZero13)

<details>
<summary>Changes</summary>

This patch fixes a missed optimization where LLVM fails to convert a `sext` to a `zext` for an induction variable with a conditional increment (e.g., `i++` inside an `if` block).
In `computeKnownBits`, LLVM uses `matchSimpleRecurrence` to inductively prove properties about PHI nodes (such as non-negativity via `nsw`). However, for a conditional increment, the backedge value is an intermediate PHI node that selects between the unchanged value (identity) and the incremented value (the step). Because this is not a direct `BinaryOperator`, `matchSimpleRecurrence` fails, and the inductive reasoning is skipped.

---
Full diff: https://github.com/llvm/llvm-project/pull/215913.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/ValueTracking.cpp (+38-1) 
- (added) llvm/test/Transforms/InstCombine/sext-zext-conditional-incr.ll (+298) 


``````````diff
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 44a1240f5635a..2578d8caa4719 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1807,7 +1807,44 @@ static void computeKnownBitsFromOperator(const Operator *I,
     const PHINode *P = cast<PHINode>(I);
     BinaryOperator *BO = nullptr;
     Value *R = nullptr, *L = nullptr;
-    if (matchSimpleRecurrence(P, BO, R, L)) {
+    if (!matchSimpleRecurrence(P, BO, R, L) && P->getNumIncomingValues() == 2) {
+      // Match a conditional recurrence where the backedge value is a PHI
+      // selecting between the outer PHI (identity) and a BinaryOperator
+      // applied to the outer PHI (conditional step). For example:
+      //   %iv = phi [0, %entry], [%merge, %backedge]
+      //   %merge = phi [%iv, %block1], [%iv.next, %block2]
+      //   %iv.next = add nsw %iv, 1
+      // The inductive known-bits reasoning (trailing zeros, nsw
+      // non-negativity) is valid for conditional steps because the identity
+      // path trivially preserves any inductive property.
+      for (unsigned Idx = 0; Idx != 2; ++Idx) {
+        auto *IncPhi = dyn_cast<PHINode>(P->getIncomingValue(Idx));
+        if (!IncPhi || IncPhi->getNumIncomingValues() != 2)
+          continue;
+
+        Value *Inc0 = IncPhi->getIncomingValue(0);
+        Value *Inc1 = IncPhi->getIncomingValue(1);
+        if (Inc0 != P && Inc1 != P)
+          continue;
+
+        Value *StepOp = (Inc0 == P) ? Inc1 : Inc0;
+        auto *Op = dyn_cast<BinaryOperator>(StepOp);
+        if (!Op)
+          continue;
+
+        Value *StepLHS = Op->getOperand(0);
+        Value *StepRHS = Op->getOperand(1);
+        if (StepLHS != P && StepRHS != P)
+          continue;
+
+        BO = Op;
+        R = P->getIncomingValue(1 - Idx);
+        L = (StepLHS == P) ? StepRHS : StepLHS;
+        break;
+      }
+    }
+
+    if (BO) {
       // Handle the case of a simple two-predecessor recurrence PHI.
       // There's a lot more that could theoretically be done here, but
       // this is sufficient to catch some interesting cases.
diff --git a/llvm/test/Transforms/InstCombine/sext-zext-conditional-incr.ll b/llvm/test/Transforms/InstCombine/sext-zext-conditional-incr.ll
new file mode 100644
index 0000000000000..b80811b5e6f11
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/sext-zext-conditional-incr.ll
@@ -0,0 +1,298 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; Test that sext is converted to zext for conditional-increment induction
+; variables where the IV starts at 0, only increments by 1 with nsw, and
+; is provably non-negative.
+
+; A while loop with conditional increment.
+; %i.07 starts at 0, conditionally increments by 1 (nsw), so it's always
+; non-negative. The sext should become zext nneg.
+define void @conditional_incr_sext(ptr noundef writeonly %out, i32 noundef %max_out, ptr noundef readonly %list) {
+; CHECK-LABEL: @conditional_incr_sext(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[LIST:%.*]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT6:%.*]] = icmp eq ptr [[TMP0]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT6]], label [[WHILE_END:%.*]], label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi ptr [ [[TMP2:%.*]], [[CLEANUP:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8_PN:%.*]] = phi ptr [ [[INCDEC_PTR8:%.*]], [[CLEANUP]] ], [ [[LIST]], [[ENTRY]] ]
+; CHECK-NEXT:    [[I_07:%.*]] = phi i32 [ [[I_2:%.*]], [[CLEANUP]] ], [ 0, [[ENTRY]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8]] = getelementptr inbounds nuw i8, ptr [[INCDEC_PTR8_PN]], i64 8
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[I_07]], [[MAX_OUT:%.*]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[CLEANUP]]
+; CHECK:       if.then:
+; CHECK-NEXT:    [[INC:%.*]] = add nuw nsw i32 [[I_07]], 1
+; CHECK-NEXT:    [[IDXPROM:%.*]] = zext nneg i32 [[I_07]] to i64
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw [8 x i8], ptr [[OUT:%.*]], i64 [[IDXPROM]]
+; CHECK-NEXT:    store ptr [[TMP1]], ptr [[ARRAYIDX]], align 8
+; CHECK-NEXT:    br label [[CLEANUP]]
+; CHECK:       cleanup:
+; CHECK-NEXT:    [[I_2]] = phi i32 [ [[I_07]], [[WHILE_BODY]] ], [ [[INC]], [[IF_THEN]] ]
+; CHECK-NEXT:    [[TMP2]] = load ptr, ptr [[INCDEC_PTR8]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq ptr [[TMP2]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; CHECK:       while.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %0 = load ptr, ptr %list, align 8
+  %tobool.not6 = icmp eq ptr %0, null
+  br i1 %tobool.not6, label %while.end, label %while.body
+
+while.body:
+  %1 = phi ptr [ %2, %cleanup ], [ %0, %entry ]
+  %incdec.ptr8.pn = phi ptr [ %incdec.ptr8, %cleanup ], [ %list, %entry ]
+  %i.07 = phi i32 [ %i.2, %cleanup ], [ 0, %entry ]
+  %incdec.ptr8 = getelementptr inbounds nuw i8, ptr %incdec.ptr8.pn, i64 8
+  %cmp = icmp slt i32 %i.07, %max_out
+  br i1 %cmp, label %if.then, label %cleanup
+
+if.then:
+  %inc = add nsw i32 %i.07, 1
+  %idxprom = sext i32 %i.07 to i64
+  %arrayidx = getelementptr inbounds [8 x i8], ptr %out, i64 %idxprom
+  store ptr %1, ptr %arrayidx, align 8
+  br label %cleanup
+
+cleanup:
+  %i.2 = phi i32 [ %i.07, %while.body ], [ %inc, %if.then ]
+  %2 = load ptr, ptr %incdec.ptr8, align 8
+  %tobool.not = icmp eq ptr %2, null
+  br i1 %tobool.not, label %while.end, label %while.body
+
+while.end:
+  ret void
+}
+
+; Negative test: no nsw on the add, can't prove non-negative.
+define void @conditional_incr_sext_no_nsw(ptr noundef writeonly %out, i32 noundef %max_out, ptr noundef readonly %list) {
+; CHECK-LABEL: @conditional_incr_sext_no_nsw(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[LIST:%.*]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT6:%.*]] = icmp eq ptr [[TMP0]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT6]], label [[WHILE_END:%.*]], label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi ptr [ [[TMP2:%.*]], [[CLEANUP:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8_PN:%.*]] = phi ptr [ [[INCDEC_PTR8:%.*]], [[CLEANUP]] ], [ [[LIST]], [[ENTRY]] ]
+; CHECK-NEXT:    [[I_07:%.*]] = phi i32 [ [[I_2:%.*]], [[CLEANUP]] ], [ 0, [[ENTRY]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8]] = getelementptr inbounds nuw i8, ptr [[INCDEC_PTR8_PN]], i64 8
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[I_07]], [[MAX_OUT:%.*]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[CLEANUP]]
+; CHECK:       if.then:
+; CHECK-NEXT:    [[INC:%.*]] = add i32 [[I_07]], 1
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[I_07]] to i64
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [8 x i8], ptr [[OUT:%.*]], i64 [[IDXPROM]]
+; CHECK-NEXT:    store ptr [[TMP1]], ptr [[ARRAYIDX]], align 8
+; CHECK-NEXT:    br label [[CLEANUP]]
+; CHECK:       cleanup:
+; CHECK-NEXT:    [[I_2]] = phi i32 [ [[I_07]], [[WHILE_BODY]] ], [ [[INC]], [[IF_THEN]] ]
+; CHECK-NEXT:    [[TMP2]] = load ptr, ptr [[INCDEC_PTR8]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq ptr [[TMP2]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; CHECK:       while.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %0 = load ptr, ptr %list, align 8
+  %tobool.not6 = icmp eq ptr %0, null
+  br i1 %tobool.not6, label %while.end, label %while.body
+
+while.body:
+  %1 = phi ptr [ %2, %cleanup ], [ %0, %entry ]
+  %incdec.ptr8.pn = phi ptr [ %incdec.ptr8, %cleanup ], [ %list, %entry ]
+  %i.07 = phi i32 [ %i.2, %cleanup ], [ 0, %entry ]
+  %incdec.ptr8 = getelementptr inbounds nuw i8, ptr %incdec.ptr8.pn, i64 8
+  %cmp = icmp slt i32 %i.07, %max_out
+  br i1 %cmp, label %if.then, label %cleanup
+
+if.then:
+  %inc = add i32 %i.07, 1
+  %idxprom = sext i32 %i.07 to i64
+  %arrayidx = getelementptr inbounds [8 x i8], ptr %out, i64 %idxprom
+  store ptr %1, ptr %arrayidx, align 8
+  br label %cleanup
+
+cleanup:
+  %i.2 = phi i32 [ %i.07, %while.body ], [ %inc, %if.then ]
+  %2 = load ptr, ptr %incdec.ptr8, align 8
+  %tobool.not = icmp eq ptr %2, null
+  br i1 %tobool.not, label %while.end, label %while.body
+
+while.end:
+  ret void
+}
+
+; Negative test: start value is not known non-negative.
+define void @conditional_incr_sext_negative_start(ptr noundef writeonly %out, i32 noundef %max_out, ptr noundef readonly %list, i32 %start) {
+; CHECK-LABEL: @conditional_incr_sext_negative_start(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[LIST:%.*]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT6:%.*]] = icmp eq ptr [[TMP0]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT6]], label [[WHILE_END:%.*]], label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi ptr [ [[TMP2:%.*]], [[CLEANUP:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8_PN:%.*]] = phi ptr [ [[INCDEC_PTR8:%.*]], [[CLEANUP]] ], [ [[LIST]], [[ENTRY]] ]
+; CHECK-NEXT:    [[I_07:%.*]] = phi i32 [ [[I_2:%.*]], [[CLEANUP]] ], [ [[START:%.*]], [[ENTRY]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8]] = getelementptr inbounds nuw i8, ptr [[INCDEC_PTR8_PN]], i64 8
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[I_07]], [[MAX_OUT:%.*]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[CLEANUP]]
+; CHECK:       if.then:
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[I_07]], 1
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[I_07]] to i64
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [8 x i8], ptr [[OUT:%.*]], i64 [[IDXPROM]]
+; CHECK-NEXT:    store ptr [[TMP1]], ptr [[ARRAYIDX]], align 8
+; CHECK-NEXT:    br label [[CLEANUP]]
+; CHECK:       cleanup:
+; CHECK-NEXT:    [[I_2]] = phi i32 [ [[I_07]], [[WHILE_BODY]] ], [ [[INC]], [[IF_THEN]] ]
+; CHECK-NEXT:    [[TMP2]] = load ptr, ptr [[INCDEC_PTR8]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq ptr [[TMP2]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; CHECK:       while.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %0 = load ptr, ptr %list, align 8
+  %tobool.not6 = icmp eq ptr %0, null
+  br i1 %tobool.not6, label %while.end, label %while.body
+
+while.body:
+  %1 = phi ptr [ %2, %cleanup ], [ %0, %entry ]
+  %incdec.ptr8.pn = phi ptr [ %incdec.ptr8, %cleanup ], [ %list, %entry ]
+  %i.07 = phi i32 [ %i.2, %cleanup ], [ %start, %entry ]
+  %incdec.ptr8 = getelementptr inbounds nuw i8, ptr %incdec.ptr8.pn, i64 8
+  %cmp = icmp slt i32 %i.07, %max_out
+  br i1 %cmp, label %if.then, label %cleanup
+
+if.then:
+  %inc = add nsw i32 %i.07, 1
+  %idxprom = sext i32 %i.07 to i64
+  %arrayidx = getelementptr inbounds [8 x i8], ptr %out, i64 %idxprom
+  store ptr %1, ptr %arrayidx, align 8
+  br label %cleanup
+
+cleanup:
+  %i.2 = phi i32 [ %i.07, %while.body ], [ %inc, %if.then ]
+  %2 = load ptr, ptr %incdec.ptr8, align 8
+  %tobool.not = icmp eq ptr %2, null
+  br i1 %tobool.not, label %while.end, label %while.body
+
+while.end:
+  ret void
+}
+
+; Negative test: step is negative (decrement), not non-negative.
+define void @conditional_decr_sext(ptr noundef writeonly %out, i32 noundef %max_out, ptr noundef readonly %list) {
+; CHECK-LABEL: @conditional_decr_sext(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[LIST:%.*]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT6:%.*]] = icmp eq ptr [[TMP0]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT6]], label [[WHILE_END:%.*]], label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi ptr [ [[TMP2:%.*]], [[CLEANUP:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8_PN:%.*]] = phi ptr [ [[INCDEC_PTR8:%.*]], [[CLEANUP]] ], [ [[LIST]], [[ENTRY]] ]
+; CHECK-NEXT:    [[I_07:%.*]] = phi i32 [ [[I_2:%.*]], [[CLEANUP]] ], [ 0, [[ENTRY]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8]] = getelementptr inbounds nuw i8, ptr [[INCDEC_PTR8_PN]], i64 8
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[I_07]], [[MAX_OUT:%.*]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[CLEANUP]]
+; CHECK:       if.then:
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[I_07]], -1
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[I_07]] to i64
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [8 x i8], ptr [[OUT:%.*]], i64 [[IDXPROM]]
+; CHECK-NEXT:    store ptr [[TMP1]], ptr [[ARRAYIDX]], align 8
+; CHECK-NEXT:    br label [[CLEANUP]]
+; CHECK:       cleanup:
+; CHECK-NEXT:    [[I_2]] = phi i32 [ [[I_07]], [[WHILE_BODY]] ], [ [[INC]], [[IF_THEN]] ]
+; CHECK-NEXT:    [[TMP2]] = load ptr, ptr [[INCDEC_PTR8]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq ptr [[TMP2]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; CHECK:       while.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %0 = load ptr, ptr %list, align 8
+  %tobool.not6 = icmp eq ptr %0, null
+  br i1 %tobool.not6, label %while.end, label %while.body
+
+while.body:
+  %1 = phi ptr [ %2, %cleanup ], [ %0, %entry ]
+  %incdec.ptr8.pn = phi ptr [ %incdec.ptr8, %cleanup ], [ %list, %entry ]
+  %i.07 = phi i32 [ %i.2, %cleanup ], [ 0, %entry ]
+  %incdec.ptr8 = getelementptr inbounds nuw i8, ptr %incdec.ptr8.pn, i64 8
+  %cmp = icmp slt i32 %i.07, %max_out
+  br i1 %cmp, label %if.then, label %cleanup
+
+if.then:
+  %inc = add nsw i32 %i.07, -1
+  %idxprom = sext i32 %i.07 to i64
+  %arrayidx = getelementptr inbounds [8 x i8], ptr %out, i64 %idxprom
+  store ptr %1, ptr %arrayidx, align 8
+  br label %cleanup
+
+cleanup:
+  %i.2 = phi i32 [ %i.07, %while.body ], [ %inc, %if.then ]
+  %2 = load ptr, ptr %incdec.ptr8, align 8
+  %tobool.not = icmp eq ptr %2, null
+  br i1 %tobool.not, label %while.end, label %while.body
+
+while.end:
+  ret void
+}
+
+; Negative test: non-commutative operation (sub) with swapped operands.
+define void @conditional_sub_swapped_sext(ptr noundef writeonly %out, i32 noundef %max_out, ptr noundef readonly %list) {
+; CHECK-LABEL: @conditional_sub_swapped_sext(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[LIST:%.*]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT6:%.*]] = icmp eq ptr [[TMP0]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT6]], label [[WHILE_END:%.*]], label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi ptr [ [[TMP2:%.*]], [[CLEANUP:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8_PN:%.*]] = phi ptr [ [[INCDEC_PTR8:%.*]], [[CLEANUP]] ], [ [[LIST]], [[ENTRY]] ]
+; CHECK-NEXT:    [[I_07:%.*]] = phi i32 [ [[I_2:%.*]], [[CLEANUP]] ], [ 0, [[ENTRY]] ]
+; CHECK-NEXT:    [[INCDEC_PTR8]] = getelementptr inbounds nuw i8, ptr [[INCDEC_PTR8_PN]], i64 8
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[I_07]], [[MAX_OUT:%.*]]
+; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[CLEANUP]]
+; CHECK:       if.then:
+; CHECK-NEXT:    [[INC:%.*]] = sub nsw i32 1, [[I_07]]
+; CHECK-NEXT:    [[IDXPROM:%.*]] = sext i32 [[I_07]] to i64
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [8 x i8], ptr [[OUT:%.*]], i64 [[IDXPROM]]
+; CHECK-NEXT:    store ptr [[TMP1]], ptr [[ARRAYIDX]], align 8
+; CHECK-NEXT:    br label [[CLEANUP]]
+; CHECK:       cleanup:
+; CHECK-NEXT:    [[I_2]] = phi i32 [ [[I_07]], [[WHILE_BODY]] ], [ [[INC]], [[IF_THEN]] ]
+; CHECK-NEXT:    [[TMP2]] = load ptr, ptr [[INCDEC_PTR8]], align 8
+; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq ptr [[TMP2]], null
+; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; CHECK:       while.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  %0 = load ptr, ptr %list, align 8
+  %tobool.not6 = icmp eq ptr %0, null
+  br i1 %tobool.not6, label %while.end, label %while.body
+
+while.body:
+  %1 = phi ptr [ %2, %cleanup ], [ %0, %entry ]
+  %incdec.ptr8.pn = phi ptr [ %incdec.ptr8, %cleanup ], [ %list, %entry ]
+  %i.07 = phi i32 [ %i.2, %cleanup ], [ 0, %entry ]
+  %incdec.ptr8 = getelementptr inbounds nuw i8, ptr %incdec.ptr8.pn, i64 8
+  %cmp = icmp slt i32 %i.07, %max_out
+  br i1 %cmp, label %if.then, label %cleanup
+
+if.then:
+  %inc = sub nsw i32 1, %i.07
+  %idxprom = sext i32 %i.07 to i64
+  %arrayidx = getelementptr inbounds [8 x i8], ptr %out, i64 %idxprom
+  store ptr %1, ptr %arrayidx, align 8
+  br label %cleanup
+
+cleanup:
+  %i.2 = phi i32 [ %i.07, %while.body ], [ %inc, %if.then ]
+  %2 = load ptr, ptr %incdec.ptr8, align 8
+  %tobool.not = icmp eq ptr %2, null
+  br i1 %tobool.not, label %while.end, label %while.body
+
+while.end:
+  ret void
+}

``````````

</details>


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


More information about the llvm-commits mailing list