[PATCH] D151541: [ValueTracking] Implied conditions for lshr
Joshua Cao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 21:08:40 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb9f1aaddac0: [ValueTracking] Implied conditions for lshr (authored by caojoshua).
Changed prior to commit:
https://reviews.llvm.org/D151541?vs=525972&id=529148#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151541/new/
https://reviews.llvm.org/D151541
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/implies.ll
Index: llvm/test/Transforms/InstSimplify/implies.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/implies.ll
+++ llvm/test/Transforms/InstSimplify/implies.ll
@@ -449,9 +449,8 @@
; CHECK-LABEL: @test_shift(
; CHECK-NEXT: [[LSHR:%.*]] = lshr i64 [[X:%.*]], [[SHIFT:%.*]]
; CHECK-NEXT: [[ICMP1:%.*]] = icmp ugt i64 [[LSHR]], [[Y:%.*]]
-; CHECK-NEXT: [[ICMP2:%.*]] = icmp ugt i64 [[X]], [[Y]]
; CHECK-NEXT: call void @llvm.assume(i1 [[ICMP1]])
-; CHECK-NEXT: ret i1 [[ICMP2]]
+; CHECK-NEXT: ret i1 true
;
%lshr = lshr i64 %x, %shift
%icmp1 = icmp ugt i64 %lshr, %y
@@ -479,11 +478,7 @@
; i <u L ==> i >> C <u L
define i1 @lshr_constant(i32 %length.i, i32 %i) {
; CHECK-LABEL: @lshr_constant(
-; CHECK-NEXT: [[SHL:%.*]] = lshr i32 [[I:%.*]], 1
-; CHECK-NEXT: [[VAR29:%.*]] = icmp ult i32 [[I]], [[LENGTH_I:%.*]]
-; CHECK-NEXT: [[VAR30:%.*]] = icmp ult i32 [[SHL]], [[LENGTH_I]]
-; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR29]], [[VAR30]]
-; CHECK-NEXT: ret i1 [[RES]]
+; CHECK-NEXT: ret i1 true
;
%shl = lshr i32 %i, 1
%var29 = icmp ult i32 %i, %length.i
@@ -495,11 +490,7 @@
; i <u L ==> i >> V <u L
define i1 @lshr_value(i32 %length.i, i32 %i, i32 %v) {
; CHECK-LABEL: @lshr_value(
-; CHECK-NEXT: [[SHL:%.*]] = lshr i32 [[I:%.*]], [[V:%.*]]
-; CHECK-NEXT: [[VAR29:%.*]] = icmp ult i32 [[I]], [[LENGTH_I:%.*]]
-; CHECK-NEXT: [[VAR30:%.*]] = icmp ult i32 [[SHL]], [[LENGTH_I]]
-; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR29]], [[VAR30]]
-; CHECK-NEXT: ret i1 [[RES]]
+; CHECK-NEXT: ret i1 true
;
%shl = lshr i32 %i, %v
%var29 = icmp ult i32 %i, %length.i
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -7913,6 +7913,10 @@
if (match(RHS, m_NUWAdd(m_Specific(LHS), m_APInt(C))))
return true;
+ // RHS >> V u<= RHS for any V
+ if (match(LHS, m_LShr(m_Specific(RHS), m_Value())))
+ return true;
+
// Match A to (X +_{nuw} CA) and B to (X +_{nuw} CB)
auto MatchNUWAddsToSameValue = [&](const Value *A, const Value *B,
const Value *&X,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151541.529148.patch
Type: text/x-patch
Size: 2296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230607/ab66c6fd/attachment.bin>
More information about the llvm-commits
mailing list