[PATCH] D140405: [CVP] Simplify SRem when constantrange abs(lhs) < abs(rhs)
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 20 23:04:29 PST 2022
StephenFan updated this revision to Diff 484472.
StephenFan added a comment.
Only simplify LHS.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140405/new/
https://reviews.llvm.org/D140405
Files:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/CorrelatedValuePropagation/srem.ll
Index: llvm/test/Transforms/CorrelatedValuePropagation/srem.ll
===================================================================
--- llvm/test/Transforms/CorrelatedValuePropagation/srem.ll
+++ llvm/test/Transforms/CorrelatedValuePropagation/srem.ll
@@ -523,8 +523,7 @@
; CHECK-NEXT: [[AND_COND:%.*]] = and i1 [[AND_X]], [[Y_CMP]]
; CHECK-NEXT: br i1 [[AND_COND]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.else:
-; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[REM]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], [[X]]
; CHECK-NEXT: ret void
; CHECK: if.then:
; CHECK-NEXT: ret void
@@ -558,8 +557,7 @@
; CHECK-NEXT: [[AND_COND:%.*]] = and i1 [[AND_X]], [[AND_Y]]
; CHECK-NEXT: br i1 [[AND_COND]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.else:
-; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[REM]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], [[X]]
; CHECK-NEXT: ret void
; CHECK: if.then:
; CHECK-NEXT: ret void
@@ -595,8 +593,7 @@
; CHECK-NEXT: [[AND_COND:%.*]] = and i1 [[AND_X]], [[AND_Y]]
; CHECK-NEXT: br i1 [[AND_COND]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.else:
-; CHECK-NEXT: [[REM:%.*]] = srem i8 [[X]], [[Y]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[REM]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], [[X]]
; CHECK-NEXT: ret void
; CHECK: if.then:
; CHECK-NEXT: ret void
Index: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -843,6 +843,15 @@
if (SDI->getType()->isVectorTy())
return false;
+ ConstantRange LCR = LVI->getConstantRange(SDI->getOperand(0), SDI);
+ ConstantRange RCR = LVI->getConstantRange(SDI->getOperand(1), SDI);
+
+ if (LCR.abs().icmp(CmpInst::ICMP_ULT, RCR.abs())) {
+ SDI->replaceAllUsesWith(SDI->getOperand(0));
+ SDI->eraseFromParent();
+ return true;
+ }
+
struct Operand {
Value *V;
Domain D;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140405.484472.patch
Type: text/x-patch
Size: 2257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221221/94aed7f9/attachment.bin>
More information about the llvm-commits
mailing list