[llvm] fedc954 - [SCEV] Recognize @llvm.usub.sat as `%x - (umin %x, %y)`
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 10:26:39 PDT 2020
Author: Roman Lebedev
Date: 2020-09-21T20:25:54+03:00
New Revision: fedc9549d50d80f74169ecce4d0d0648a62249f0
URL: https://github.com/llvm/llvm-project/commit/fedc9549d50d80f74169ecce4d0d0648a62249f0
DIFF: https://github.com/llvm/llvm-project/commit/fedc9549d50d80f74169ecce4d0d0648a62249f0.diff
LOG: [SCEV] Recognize @llvm.usub.sat as `%x - (umin %x, %y)`
----------------------------------------
define i32 @src(i32 %x, i32 %y) {
%0:
%r = usub_sat i32 %x, %y
ret i32 %r
}
=>
define i32 @tgt(i32 %x, i32 %y) {
%0:
%t0 = umin i32 %x, %y
%r = sub nuw i32 %x, %t0
ret i32 %r
}
Transformation seems to be correct!
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 11e8740d2f50..47422035ee89 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6359,6 +6359,12 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
case Intrinsic::smin:
return getSMinExpr(getSCEV(II->getArgOperand(0)),
getSCEV(II->getArgOperand(1)));
+ case Intrinsic::usub_sat: {
+ const SCEV *X = getSCEV(II->getArgOperand(0));
+ const SCEV *Y = getSCEV(II->getArgOperand(1));
+ const SCEV *ClampedY = getUMinExpr(X, Y);
+ return getMinusSCEV(X, ClampedY, SCEV::FlagNUW);
+ }
default:
break;
}
diff --git a/llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll b/llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll
index b49cc710892a..0a054eea1491 100644
--- a/llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll
+++ b/llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll
@@ -35,7 +35,7 @@ define i32 @usub_sat(i32 %x, i32 %y) {
; CHECK-LABEL: 'usub_sat'
; CHECK-NEXT: Classifying expressions for: @usub_sat
; CHECK-NEXT: %z = call i32 @llvm.usub.sat.i32(i32 %x, i32 %y)
-; CHECK-NEXT: --> %z U: full-set S: full-set
+; CHECK-NEXT: --> ((-1 * (%x umin %y)) + %x) U: full-set S: full-set
; CHECK-NEXT: Determining loop execution counts for: @usub_sat
;
%z = call i32 @llvm.usub.sat.i32(i32 %x, i32 %y)
More information about the llvm-commits
mailing list