[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!
This commit is contained in:
Roman Lebedev 2020-09-21 18:05:47 +03:00
parent 0592de550f
commit fedc9549d5
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 7 additions and 1 deletions

View File

@ -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;
}

View File

@ -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)