[PATCH] D140405: [CVP] Simplify SRem when constantrange abs(lhs) < abs(rhs)
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 3 06:53:22 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b25a0bcb14b: [CVP] Simplify SRem when constantrange abs(lhs) < abs(rhs) (authored by StephenFan).
Changed prior to commit:
https://reviews.llvm.org/D140405?vs=484472&id=485985#toc
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: ret i8 [[REM]]
+; CHECK-NEXT: ret i8 [[X]]
; CHECK: if.then:
; CHECK-NEXT: ret i8 0
;
@@ -556,8 +555,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: ret i8 [[REM]]
+; CHECK-NEXT: ret i8 [[X]]
; CHECK: if.then:
; CHECK-NEXT: ret i8 0
;
@@ -591,8 +589,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: ret i8 [[REM]]
+; CHECK-NEXT: ret i8 [[X]]
; CHECK: if.then:
; CHECK-NEXT: ret i8 0
;
Index: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -905,6 +905,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.485985.patch
Type: text/x-patch
Size: 2035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230103/21f6f5e0/attachment.bin>
More information about the llvm-commits
mailing list