[llvm] [llvm][ipsccp/sccp] Strengthen range analysis in SCCPSolver (PR #111716)
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 20:53:21 PDT 2024
================
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
+
+define i32 @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT: init:
+; CHECK-NEXT: br label %[[OUTER_LOOP_CONTROL:.*]]
+; CHECK: outer.loop.control:
+; CHECK-NEXT: [[X_0:%.*]] = phi i32 [ 0, [[INIT:%.*]] ], [ [[X_OUTER:%.*]], [[OUTER_LOOP_INC:%.*]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[X_0]], 10
+; CHECK-NEXT: br i1 [[TMP0]], label %[[INNER_LOOP_CONTROL:.*]], label %[[EXIT:.*]]
+; CHECK: inner.loop.control:
+; CHECK-NEXT: br label [[OUTER_LOOP_INC]]
+; CHECK: outer.loop.inc:
+; CHECK-NEXT: [[X_OUTER]] = add nsw i32 [[X_0]], 2
+; CHECK-NEXT: br label %[[OUTER_LOOP_CONTROL]]
+; CHECK: exit:
+; CHECK-NEXT: ret i32 [[X_0]]
+;
+init:
+ br label %outer.loop.control
+
+outer.loop.control: ; preds = %init, %outer.loop.inc
+ %x.0 = phi i32 [ 0, %init ], [ %x.outer, %outer.loop.inc ]
+ %0 = icmp slt i32 %x.0, 10
+ br i1 %0, label %inner.loop.control, label %exit
+
+inner.loop.control: ; preds = %outer.loop.control, %inner.loop.body
+ %x.1 = phi i32 [ %x.0, %outer.loop.control ], [ %x.inner, %inner.loop.body ]
+ %1 = icmp sgt i32 %x.1, 20
----------------
dcci wrote:
> @dtcxzyw -- this can happen (and we saw it happening) in real code. Imagine a round of inlining followed by function passes that leaves some dead code behind.
Also GCC seems to get this one right, so the optimization is not that far-fetched.
https://godbolt.org/z/rMMdTsr7f
https://github.com/llvm/llvm-project/pull/111716
More information about the llvm-commits
mailing list