[llvm] aa41fe6 - [tests] Precommit tests for phi recusion limits in known bits
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 17 14:04:02 PDT 2022
Author: Philip Reames
Date: 2022-08-17T14:03:10-07:00
New Revision: aa41fe664ab203257e2336bd8f33f5dcc91b5101
URL: https://github.com/llvm/llvm-project/commit/aa41fe664ab203257e2336bd8f33f5dcc91b5101
DIFF: https://github.com/llvm/llvm-project/commit/aa41fe664ab203257e2336bd8f33f5dcc91b5101.diff
LOG: [tests] Precommit tests for phi recusion limits in known bits
Added:
llvm/test/Transforms/InstCombine/known-phi-recurse.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/known-phi-recurse.ll b/llvm/test/Transforms/InstCombine/known-phi-recurse.ll
new file mode 100644
index 0000000000000..07d6bf2f6517e
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/known-phi-recurse.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+;
+; Tests to show cases where computeKnownBits should be able to determine
+; the known bits of a phi based on limited recursion.
+;
+
+declare i64 @llvm.ctpop.i64(i64)
+
+
+define i32 @single_entry_phi(i64 %x, i1 %c) {
+; CHECK-LABEL: @single_entry_phi(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[BODY:%.*]]
+; CHECK: body:
+; CHECK-NEXT: br i1 [[C:%.*]], label [[END:%.*]], label [[BODY]]
+; CHECK: end:
+; CHECK-NEXT: [[Y:%.*]] = call i64 @llvm.ctpop.i64(i64 [[X:%.*]]), !range [[RNG0:![0-9]+]]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[Y]] to i32
+; CHECK-NEXT: ret i32 [[TRUNC]]
+;
+entry:
+ %y = call i64 @llvm.ctpop.i64(i64 %x)
+ %trunc = trunc i64 %y to i32
+ br label %body
+body:
+ br i1 %c, label %end, label %body
+end:
+ %phi = phi i32 [ %trunc, %body ]
+ %res = and i32 %phi, 127
+ ret i32 %res
+}
+
+
+define i32 @two_entry_phi_with_constant(i64 %x, i1 %c) {
+; CHECK-LABEL: @two_entry_phi_with_constant(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[Y:%.*]] = call i64 @llvm.ctpop.i64(i64 [[X:%.*]]), !range [[RNG0]]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[Y]] to i32
+; CHECK-NEXT: br i1 [[C:%.*]], label [[END:%.*]], label [[BODY:%.*]]
+; CHECK: body:
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[TRUNC]], [[ENTRY:%.*]] ], [ 255, [[BODY]] ]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[PHI]], 255
+; CHECK-NEXT: ret i32 [[RES]]
+;
+entry:
+ %y = call i64 @llvm.ctpop.i64(i64 %x)
+ %trunc = trunc i64 %y to i32
+ br i1 %c, label %end, label %body
+body:
+ br label %end
+end:
+ %phi = phi i32 [ %trunc, %entry ], [ 255, %body ]
+ %res = and i32 %phi, 255
+ ret i32 %res
+}
+
+define i32 @two_entry_phi_non_constant(i64 %x, i64 %x2, i1 %c) {
+; CHECK-LABEL: @two_entry_phi_non_constant(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[Y:%.*]] = call i64 @llvm.ctpop.i64(i64 [[X:%.*]]), !range [[RNG0]]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[Y]] to i32
+; CHECK-NEXT: br i1 [[C:%.*]], label [[END:%.*]], label [[BODY:%.*]]
+; CHECK: body:
+; CHECK-NEXT: [[Y2:%.*]] = call i64 @llvm.ctpop.i64(i64 [[X2:%.*]]), !range [[RNG0]]
+; CHECK-NEXT: [[TRUNC2:%.*]] = trunc i64 [[Y2]] to i32
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[TRUNC]], [[ENTRY:%.*]] ], [ [[TRUNC2]], [[BODY]] ]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[PHI]], 255
+; CHECK-NEXT: ret i32 [[RES]]
+;
+entry:
+ %y = call i64 @llvm.ctpop.i64(i64 %x)
+ %trunc = trunc i64 %y to i32
+ br i1 %c, label %end, label %body
+body:
+ %y2 = call i64 @llvm.ctpop.i64(i64 %x2)
+ %trunc2 = trunc i64 %y2 to i32
+ br label %end
+end:
+ %phi = phi i32 [ %trunc, %entry ], [ %trunc2, %body ]
+ %res = and i32 %phi, 255
+ ret i32 %res
+}
+
+define i32 @neg_many_branches(i64 %x) {
+; CHECK-LABEL: @neg_many_branches(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[Y:%.*]] = call i64 @llvm.ctpop.i64(i64 [[X:%.*]]), !range [[RNG0]]
+; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[Y]] to i32
+; CHECK-NEXT: [[TRUNC1:%.*]] = trunc i64 [[Y]] to i7
+; CHECK-NEXT: switch i7 [[TRUNC1]], label [[END:%.*]] [
+; CHECK-NEXT: i7 1, label [[ONE:%.*]]
+; CHECK-NEXT: i7 2, label [[TWO:%.*]]
+; CHECK-NEXT: i7 3, label [[THREE:%.*]]
+; CHECK-NEXT: i7 4, label [[FOUR:%.*]]
+; CHECK-NEXT: ]
+; CHECK: one:
+; CHECK-NEXT: [[A:%.*]] = add nuw nsw i32 [[TRUNC]], 1
+; CHECK-NEXT: br label [[END]]
+; CHECK: two:
+; CHECK-NEXT: [[B:%.*]] = add nuw nsw i32 [[TRUNC]], 2
+; CHECK-NEXT: br label [[END]]
+; CHECK: three:
+; CHECK-NEXT: [[C:%.*]] = add nuw nsw i32 [[TRUNC]], 3
+; CHECK-NEXT: br label [[END]]
+; CHECK: four:
+; CHECK-NEXT: [[D:%.*]] = add nuw nsw i32 [[TRUNC]], 4
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[TRUNC]], [[ENTRY:%.*]] ], [ [[A]], [[ONE]] ], [ [[B]], [[TWO]] ], [ [[C]], [[THREE]] ], [ [[D]], [[FOUR]] ]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[PHI]], 255
+; CHECK-NEXT: ret i32 [[RES]]
+;
+entry:
+ %y = call i64 @llvm.ctpop.i64(i64 %x)
+ %trunc = trunc i64 %y to i32
+ switch i32 %trunc, label %end [
+ i32 1, label %one
+ i32 2, label %two
+ i32 3, label %three
+ i32 4, label %four
+ ]
+one:
+ %a = add i32 %trunc, 1
+ br label %end
+two:
+ %b = add i32 %trunc, 2
+ br label %end
+three:
+ %c = add i32 %trunc, 3
+ br label %end
+four:
+ %d = add i32 %trunc, 4
+ br label %end
+end:
+ %phi = phi i32 [ %trunc, %entry ], [ %a, %one ], [ %b, %two ], [ %c, %three ], [ %d, %four ]
+ %res = and i32 %phi, 255
+ ret i32 %res
+}
+
More information about the llvm-commits
mailing list