[llvm] [JumpThreading] Convert `s/zext i1` to `select i1` for further unfolding (PR #89345)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 19 02:43:54 PDT 2024
================
@@ -0,0 +1,94 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -passes=jump-threading < %s | FileCheck %s
+
+; void fun(int);
+;
+; int compare1(int a, int b, int c, int d)
+; {
+; return a < b ? -1 :
+; a > b ? 1 :
+; c < d ? -1 :
+; c > d ? 1 : 0;
+; }
+;
+; void test1(int a, int b, int c, int d) {
+; int x = compare1(a, b, c, d);
+; if (x < 0)
+; fun(10);
+; else if (x > 0)
+; fun(20);
+; else
+; fun(30);
+; }
+
+declare void @fun(i32 noundef)
+
+define void @test1(i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d) {
+; CHECK-LABEL: define void @test1(
+; CHECK-SAME: i32 noundef [[A:%.*]], i32 noundef [[B:%.*]], i32 noundef [[C:%.*]], i32 noundef [[D:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: br i1 [[CMP_I]], label [[IF_THEN:%.*]], label [[COND_FALSE_I:%.*]]
+; CHECK: cond.false.i:
+; CHECK-NEXT: [[CMP1_I:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: br i1 [[CMP1_I]], label [[IF_THEN2:%.*]], label [[COND_FALSE3_I:%.*]]
+; CHECK: cond.false3.i:
+; CHECK-NEXT: [[CMP4_I:%.*]] = icmp slt i32 [[C]], [[D]]
+; CHECK-NEXT: br i1 [[CMP4_I]], label [[IF_THEN]], label [[COND_FALSE6_I:%.*]]
+; CHECK: cond.false6.i:
+; CHECK-NEXT: [[CMP7_I:%.*]] = icmp sgt i32 [[C]], [[D]]
+; CHECK-NEXT: br i1 [[CMP7_I]], label [[IF_THEN2]], label [[IF_ELSE3:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: call void @fun(i32 noundef 10)
+; CHECK-NEXT: br label [[IF_END4:%.*]]
+; CHECK: if.then2:
+; CHECK-NEXT: call void @fun(i32 noundef 20)
+; CHECK-NEXT: br label [[IF_END4]]
+; CHECK: if.else3:
+; CHECK-NEXT: [[COND12_I:%.*]] = phi i32 [ 0, [[COND_FALSE6_I]] ]
+; CHECK-NEXT: call void @fun(i32 noundef 30)
+; CHECK-NEXT: br label [[IF_END4]]
+; CHECK: if.end4:
+; CHECK-NEXT: ret void
+;
+entry:
+ %cmp.i = icmp slt i32 %a, %b
+ br i1 %cmp.i, label %compare1.exit, label %cond.false.i
+
+cond.false.i: ; preds = %entry
+ %cmp1.i = icmp sgt i32 %a, %b
+ br i1 %cmp1.i, label %compare1.exit, label %cond.false3.i
+
+cond.false3.i: ; preds = %cond.false.i
+ %cmp4.i = icmp slt i32 %c, %d
+ br i1 %cmp4.i, label %compare1.exit, label %cond.false6.i
+
+cond.false6.i: ; preds = %cond.false3.i
+ %cmp7.i = icmp sgt i32 %c, %d
+ %cond.i = zext i1 %cmp7.i to i32
----------------
nikic wrote:
Missing test for sext?
This test does not look very minimal.
https://github.com/llvm/llvm-project/pull/89345
More information about the llvm-commits
mailing list