[PATCH] D149372: [ValueTracking] Add logic for `fshl/fshr(A, B, C) != 0` if `A == B && A ! = 0`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 12:01:54 PDT 2023
goldstein.w.n created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Having `A == B` is quite common for rotate patterns.
Alive2 Links:
- https://alive2.llvm.org/ce/z/mPXi9c
- https://alive2.llvm.org/ce/z/UfDHoI
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149372
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-non-zero.ll
Index: llvm/test/Analysis/ValueTracking/known-non-zero.ll
===================================================================
--- llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -532,10 +532,7 @@
; CHECK-LABEL: @fshr_non_zero(
; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]])
-; CHECK-NEXT: [[V:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X]], i8 [[X]], i8 [[Y:%.*]])
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[V]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[OR]], 0
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: ret i1 false
;
%pred0 = icmp ne i8 %x, 0
call void @llvm.assume(i1 %pred0)
@@ -570,10 +567,7 @@
; CHECK-LABEL: @fshl_non_zero(
; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]])
-; CHECK-NEXT: [[V:%.*]] = tail call i8 @llvm.fshl.i8(i8 [[X]], i8 [[X]], i8 [[Y:%.*]])
-; CHECK-NEXT: [[OR:%.*]] = or i8 [[V]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[OR]], 0
-; CHECK-NEXT: ret i1 [[R]]
+; CHECK-NEXT: ret i1 false
;
%pred0 = icmp ne i8 %x, 0
call void @llvm.assume(i1 %pred0)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2894,6 +2894,12 @@
isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
return true;
break;
+ case Intrinsic::fshr:
+ case Intrinsic::fshl:
+ // If Op0 == Op1, this is a rotate. rotate(x, y) != 0 iff x != 0.
+ if (II->getArgOperand(0) == II->getArgOperand(1))
+ return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
+ break;
case Intrinsic::vscale:
return true;
default:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149372.517671.patch
Type: text/x-patch
Size: 1908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230427/1c434abf/attachment.bin>
More information about the llvm-commits
mailing list