[llvm] 35d916e - [ValueTracking] Add tests for getting knownbits from phi-edges; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 22 08:59:11 PDT 2023
Author: Noah Goldstein
Date: 2023-08-22T10:59:02-05:00
New Revision: 35d916e11be224ee2671c32d9efd00af928a2e3d
URL: https://github.com/llvm/llvm-project/commit/35d916e11be224ee2671c32d9efd00af928a2e3d
DIFF: https://github.com/llvm/llvm-project/commit/35d916e11be224ee2671c32d9efd00af928a2e3d.diff
LOG: [ValueTracking] Add tests for getting knownbits from phi-edges; NFC
Differential Revision: https://reviews.llvm.org/D157797
Added:
llvm/test/Analysis/ValueTracking/phi-known-bits.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Analysis/ValueTracking/phi-known-bits.ll b/llvm/test/Analysis/ValueTracking/phi-known-bits.ll
new file mode 100644
index 00000000000000..be64f9cfe07aa2
--- /dev/null
+++ b/llvm/test/Analysis/ValueTracking/phi-known-bits.ll
@@ -0,0 +1,449 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=instcombine < %s -S | FileCheck %s
+
+define i8 @phi_ugt_high_bits(i8 %x) {
+; CHECK-LABEL: @phi_ugt_high_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], -65
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp ugt i8 %x, 191
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_ult_low_bits(i8 %x) {
+; CHECK-LABEL: @phi_ult_low_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], -64
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: br label [[F]]
+; CHECK: F:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[T]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+;
+entry:
+ %cmp = icmp ult i8 %x, 192
+ br i1 %cmp, label %T, label %F
+T:
+ br label %F
+F:
+ %v = phi i8 [ %x, %entry], [-1, %T]
+ %r = and i8 %v, 64
+ ret i8 %r
+}
+
+define i8 @phi_ugt_high_bits_fail(i8 %x) {
+; CHECK-LABEL: @phi_ugt_high_bits_fail(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], -66
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp ugt i8 %x, 190
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_uge_high_bits(i8 %x) {
+; CHECK-LABEL: @phi_uge_high_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], -65
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp uge i8 %x, 192
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_uge_high_bits_fail(i8 %x) {
+; CHECK-LABEL: @phi_uge_high_bits_fail(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], 5
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp ugt i8 %x, 5
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 1
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sge_high_bits(i8 %x) {
+; CHECK-LABEL: @phi_sge_high_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 95
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 96
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sge i8 %x, 96
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 96
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sge_high_bits_fail(i8 %x) {
+; CHECK-LABEL: @phi_sge_high_bits_fail(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -2
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sge i8 %x, -1
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 1
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sgt_high_bits(i8 %x) {
+; CHECK-LABEL: @phi_sgt_high_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ 0, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], -128
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sgt i8 %x, -1
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [0, %F]
+ %r = and i8 %v, 128
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sgt_high_bits2(i8 %x) {
+; CHECK-LABEL: @phi_sgt_high_bits2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 63
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sgt i8 %x, 63
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sgt_high_bits_fail(i8 %x) {
+; CHECK-LABEL: @phi_sgt_high_bits_fail(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 62
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sgt i8 %x, 62
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_slt_high_bits(i8 %x) {
+; CHECK-LABEL: @phi_slt_high_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], -128
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp slt i8 %x, 0
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 128
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_slt_high_bits2(i8 %x) {
+; CHECK-LABEL: @phi_slt_high_bits2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -64
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ 0, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp slt i8 %x, -64
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [0, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_slt_high_bits_fail(i8 %x) {
+; CHECK-LABEL: @phi_slt_high_bits_fail(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -63
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ 0, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp slt i8 %x, -63
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [0, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sle_high_bits(i8 %x) {
+; CHECK-LABEL: @phi_sle_high_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -64
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ 0, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sle i8 %x, -65
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [0, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sle_low_bits(i8 %x) {
+; CHECK-LABEL: @phi_sle_low_bits(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 65
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: br label [[F]]
+; CHECK: F:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[T]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+;
+entry:
+ %cmp = icmp sle i8 %x, 64
+ br i1 %cmp, label %T, label %F
+T:
+ br label %F
+F:
+ %v = phi i8 [ %x, %entry], [-1, %T]
+ %r = and i8 %v, 64
+ ret i8 %r
+}
+
+define i8 @phi_sle_high_bits_fail(i8 %x) {
+; CHECK-LABEL: @phi_sle_high_bits_fail(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], -128
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sle i8 %x, 0
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 128
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_sle_high_bits_fail2(i8 %x) {
+; CHECK-LABEL: @phi_sle_high_bits_fail2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -63
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 64
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %cmp = icmp sle i8 %x, -64
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 64
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_ugt_high_bits_and_known(i8 %xx) {
+; CHECK-LABEL: @phi_ugt_high_bits_and_known(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X]], -65
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 65
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %x = or i8 %xx, 1
+ %cmp = icmp ugt i8 %x, 191
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 65
+ ret i8 %r
+F:
+ br label %T
+}
+
+define i8 @phi_ugt_high_bits_and_known_todo_high_depths(i8 %xx, i8 %y, i8 %z) {
+; CHECK-LABEL: @phi_ugt_high_bits_and_known_todo_high_depths(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[YY:%.*]] = and i8 [[Y:%.*]], -2
+; CHECK-NEXT: [[XXX:%.*]] = and i8 [[YY]], [[XX:%.*]]
+; CHECK-NEXT: [[ZZ:%.*]] = or i8 [[Z:%.*]], 1
+; CHECK-NEXT: [[X:%.*]] = add i8 [[XXX]], [[ZZ]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X]], -65
+; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
+; CHECK: T:
+; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ]
+; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 65
+; CHECK-NEXT: ret i8 [[R]]
+; CHECK: F:
+; CHECK-NEXT: br label [[T]]
+;
+entry:
+ %yy = and i8 %y, -2
+ %xxx = and i8 %xx, %yy
+ %zz = or i8 %z, 1
+ %x = add i8 %xxx, %zz
+ %cmp = icmp ugt i8 %x, 191
+ br i1 %cmp, label %T, label %F
+T:
+ %v = phi i8 [ %x, %entry], [-1, %F]
+ %r = and i8 %v, 65
+ ret i8 %r
+F:
+ br label %T
+}
More information about the llvm-commits
mailing list