Skip to content

Commit 769952d

Browse files
committed
[ValueTracking] Implement Known{Bits,NonZero,FPClass} for llvm.vector.reverse
`llvm.vector.reverse` preserves each of the elements and thus elements common to them. Alive2 doesn't support the intrin yet, but the logic seems pretty self-evident. Closes #99013
1 parent 41b876d commit 769952d

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
17101710
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
17111711
Known = KnownBits::ssub_sat(Known, Known2);
17121712
break;
1713+
// Vec reverse preserves bits from input vec.
1714+
case Intrinsic::vector_reverse:
17131715
// for min/max/and/or reduce, any bit common to each element in the
17141716
// input vec is set in the output.
17151717
case Intrinsic::vector_reduce_and:
@@ -3090,6 +3092,8 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
30903092
return isNonZeroAdd(DemandedElts, Depth, Q, BitWidth,
30913093
II->getArgOperand(0), II->getArgOperand(1),
30923094
/*NSW=*/true, /* NUW=*/false);
3095+
// Vec reverse preserves zero/non-zero status from input vec.
3096+
case Intrinsic::vector_reverse:
30933097
// umin/smin/smax/smin/or of all non-zero elements is always non-zero.
30943098
case Intrinsic::vector_reduce_or:
30953099
case Intrinsic::vector_reduce_umax:
@@ -5227,6 +5231,11 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
52275231
Known.SignBit.reset();
52285232
break;
52295233
}
5234+
// reverse preserves all characteristics of the input vec's element.
5235+
case Intrinsic::vector_reverse:
5236+
Known = computeKnownFPClass(II->getArgOperand(0), II->getFastMathFlags(),
5237+
InterestedClasses, Depth + 1, Q);
5238+
break;
52305239
case Intrinsic::trunc:
52315240
case Intrinsic::floor:
52325241
case Intrinsic::ceil:

llvm/test/Analysis/ValueTracking/known-bits.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
define <4 x i1> @vec_reverse_known_bits(<4 x i8> %xx) {
55
; CHECK-LABEL: @vec_reverse_known_bits(
6-
; CHECK-NEXT: [[X:%.*]] = or <4 x i8> [[XX:%.*]], <i8 -128, i8 -128, i8 -128, i8 -128>
7-
; CHECK-NEXT: [[REV:%.*]] = call <4 x i8> @llvm.vector.reverse.v4i8(<4 x i8> [[X]])
8-
; CHECK-NEXT: [[R:%.*]] = icmp slt <4 x i8> [[REV]], zeroinitializer
9-
; CHECK-NEXT: ret <4 x i1> [[R]]
6+
; CHECK-NEXT: ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
107
;
118
%x = or <4 x i8> %xx, <i8 128, i8 128, i8 128, i8 128>
129
%rev = call <4 x i8> @llvm.vector.reverse(<4 x i8> %x)

llvm/test/Analysis/ValueTracking/known-fpclass.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
define <4 x i1> @vector_reverse_fpclass(<4 x double> nofpclass(nzero nan) %x) {
55
; CHECK-LABEL: @vector_reverse_fpclass(
6-
; CHECK-NEXT: [[X_ABS:%.*]] = call <4 x double> @llvm.fabs.v4f64(<4 x double> [[X:%.*]])
7-
; CHECK-NEXT: [[OP:%.*]] = call <4 x double> @llvm.vector.reverse.v4f64(<4 x double> [[X_ABS]])
8-
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge <4 x double> [[OP]], zeroinitializer
9-
; CHECK-NEXT: ret <4 x i1> [[CMP]]
6+
; CHECK-NEXT: ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
107
;
118
%x.abs = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x)
129
%op = call <4 x double> @llvm.vector.reverse(<4 x double> %x.abs)

llvm/test/Analysis/ValueTracking/known-non-zero.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,10 +1499,7 @@ define i1 @trunc_nsw_nuw_non_zero_fail(i8 %xx) {
14991499

15001500
define <4 x i1> @vec_reverse_non_zero(<4 x i8> %xx) {
15011501
; CHECK-LABEL: @vec_reverse_non_zero(
1502-
; CHECK-NEXT: [[X:%.*]] = add nuw <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
1503-
; CHECK-NEXT: [[REV:%.*]] = call <4 x i8> @llvm.vector.reverse.v4i8(<4 x i8> [[X]])
1504-
; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i8> [[REV]], zeroinitializer
1505-
; CHECK-NEXT: ret <4 x i1> [[R]]
1502+
; CHECK-NEXT: ret <4 x i1> zeroinitializer
15061503
;
15071504
%x = add nuw <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
15081505
%rev = call <4 x i8> @llvm.vector.reverse(<4 x i8> %x)

0 commit comments

Comments
 (0)