diff --git a/llvm/test/Analysis/ValueTracking/phi-known-nonzero.ll b/llvm/test/Analysis/ValueTracking/phi-known-nonzero.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/ValueTracking/phi-known-nonzero.ll @@ -0,0 +1,211 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=instsimplify < %s -S | FileCheck %s + +define i1 @phi_ugt_non_zero(i8 %x) { +; CHECK-LABEL: @phi_ugt_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], 32 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; CHECK: F: +; CHECK-NEXT: br i1 true, label [[T]], label [[F]] +; +entry: + %cmp = icmp ugt i8 %x, 32 + br i1 %cmp, label %T, label %F +T: + %v = phi i8 [ %x, %entry], [-1, %F] + %r = icmp eq i8 %v, 0 + ret i1 %r +F: + br i1 true, label %T, label %F +} + +define i1 @phi_ugeh_non_zero(i8 %x) { +; CHECK-LABEL: @phi_ugeh_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[X:%.*]], 32 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; CHECK: F: +; CHECK-NEXT: br i1 true, label [[T]], label [[F]] +; +entry: + %cmp = icmp uge i8 %x, 32 + br i1 %cmp, label %T, label %F +T: + %v = phi i8 [ %x, %entry], [-1, %F] + %r = icmp eq i8 %v, 0 + ret i1 %r +F: + br i1 true, label %T, label %F +} + +define i1 @phi_ugt_non_zero_fail(i8 %x) { +; CHECK-LABEL: @phi_ugt_non_zero_fail( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], 32 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ 0, [[F]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; CHECK: F: +; CHECK-NEXT: br i1 true, label [[T]], label [[F]] +; +entry: + %cmp = icmp ugt i8 %x, 32 + br i1 %cmp, label %T, label %F +T: + %v = phi i8 [ %x, %entry], [0, %F] + %r = icmp eq i8 %v, 0 + ret i1 %r +F: + br i1 true, label %T, label %F +} + +define i1 @phi_ult_non_zero(i8 %x) { +; CHECK-LABEL: @phi_ult_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], 123 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: br i1 true, label [[F]], label [[T]] +; CHECK: F: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[T]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; +entry: + %cmp = icmp ult i8 %x, 123 + br i1 %cmp, label %T, label %F +T: + br i1 true, label %F, label %T +F: + %v = phi i8 [ %x, %entry], [-1, %T] + %r = icmp eq i8 %v, 0 + ret i1 %r +} + +define i1 @phi_ule_non_zero(i8 %x) { +; CHECK-LABEL: @phi_ule_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[X:%.*]], 123 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: br i1 true, label [[F]], label [[T]] +; CHECK: F: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[T]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; +entry: + %cmp = icmp ule i8 %x, 123 + br i1 %cmp, label %T, label %F +T: + br i1 true, label %F, label %T +F: + %v = phi i8 [ %x, %entry], [-1, %T] + %r = icmp eq i8 %v, 0 + ret i1 %r +} + +define i1 @phi_ult_non_zero_fail(i8 %x) { +; CHECK-LABEL: @phi_ult_non_zero_fail( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[X:%.*]], 123 +; CHECK-NEXT: [[X2:%.*]] = add i8 [[X]], [[X]] +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: br i1 true, label [[F]], label [[T]] +; CHECK: F: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X2]], [[ENTRY:%.*]] ], [ -1, [[T]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; +entry: + %cmp = icmp ult i8 %x, 123 + %x2 = add i8 %x, %x + br i1 %cmp, label %T, label %F +T: + br i1 true, label %F, label %T +F: + %v = phi i8 [ %x2, %entry], [-1, %T] + %r = icmp eq i8 %v, 0 + ret i1 %r +} + +define i1 @phi_ne_non_zero(i8 %x) { +; CHECK-LABEL: @phi_ne_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp ne 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:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; CHECK: F: +; CHECK-NEXT: br i1 true, label [[T]], label [[F]] +; +entry: + %cmp = icmp ne i8 %x, 0 + br i1 %cmp, label %T, label %F +T: + %v = phi i8 [ %x, %entry], [-1, %F] + %r = icmp eq i8 %v, 0 + ret i1 %r +F: + br i1 true, label %T, label %F +} + +define i1 @phi_eq_non_zero(i8 %x) { +; CHECK-LABEL: @phi_eq_non_zero( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 44 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; CHECK: F: +; CHECK-NEXT: br i1 true, label [[T]], label [[F]] +; +entry: + %cmp = icmp eq i8 %x, 44 + br i1 %cmp, label %T, label %F +T: + %v = phi i8 [ %x, %entry], [-1, %F] + %r = icmp eq i8 %v, 0 + ret i1 %r +F: + br i1 true, label %T, label %F +} + +define i1 @phi_eq_non_zero2(i8 %x) { +; CHECK-LABEL: @phi_eq_non_zero2( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 0 +; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] +; CHECK: T: +; CHECK-NEXT: br i1 true, label [[F]], label [[T]] +; CHECK: F: +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[T]] ] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0 +; CHECK-NEXT: ret i1 [[R]] +; +entry: + %cmp = icmp eq i8 %x, 0 + br i1 %cmp, label %T, label %F +T: + br i1 true, label %F, label %T +F: + %v = phi i8 [ %x, %entry], [-1, %T] + %r = icmp eq i8 %v, 0 + ret i1 %r +}