[Cost] Fix multiplication by 1

Reviewed By: ddino

Differential Revision: D7782184

fbshipit-source-id: dd3c4f1
master
Mehdi Bouaziz 7 years ago committed by Facebook Github Bot
parent 077d9a534b
commit 9c14e9d384

@ -806,18 +806,31 @@ module Bound = struct
None
let neg : t -> t = function
| MInf ->
PInf
| PInf ->
MInf
| Linear (c, x) ->
Linear (-c, SymLinear.neg x)
| MinMax (c, sign, min_max, d, x) ->
mk_MinMax (-c, Sign.neg sign, min_max, d, x)
let mult : t -> t -> t =
fun x y ->
let res_opt =
match (is_const x, is_const y) with
| _, Some n -> (
match NonZeroInt.of_int n with Some n' -> mult_const x n' | _ -> Some zero )
| Some n, _ -> (
match NonZeroInt.of_int n with Some n' -> mult_const y n' | _ -> Some zero )
| _, _ ->
None
in
Option.value res_opt ~default:PInf
let default = PInf in
match (x, is_const x, y, is_const y) with
| x, _, _, Some n | _, Some n, x, _ -> (
match NonZeroInt.of_int n with
| Some n ->
if NonZeroInt.is_one n then x
else if NonZeroInt.is_minus_one n then neg x
else mult_const x n |> Option.value ~default
| None ->
zero )
| _ ->
default
let div_const : t -> NonZeroInt.t -> t option =
@ -837,17 +850,6 @@ module Bound = struct
None
let neg : t -> t = function
| MInf ->
PInf
| PInf ->
MInf
| Linear (c, x) ->
Linear (-c, SymLinear.neg x)
| MinMax (c, sign, min_max, d, x) ->
mk_MinMax (-c, Sign.neg sign, min_max, d, x)
let get_symbols : t -> Symbol.t list = function
| MInf | PInf ->
[]

@ -81,7 +81,6 @@ int loop1_bad() {
return 0;
}
// This is currently evaluated to Top as the analysis is not powerful enough
int FN_loop2(int k) {
for (int i = 0; i < k; i++) {

@ -1,4 +1,6 @@
codetoanalyze/c/performance/cost_test.c, FN_loop2, 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
codetoanalyze/c/performance/cost_test.c, FN_loop2, 2, EXPENSIVE_EXECUTION_TIME_CALL, ERROR, [with estimated cost 11xs$1 + 3]
codetoanalyze/c/performance/cost_test.c, FN_loop2, 3, EXPENSIVE_EXECUTION_TIME_CALL, ERROR, [with estimated cost 11xs$1 + 3]
codetoanalyze/c/performance/cost_test.c, FN_loop3, 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
codetoanalyze/c/performance/cost_test.c, loop0_bad, 2, EXPENSIVE_EXECUTION_TIME_CALL, ERROR, [with estimated cost 1002]
codetoanalyze/c/performance/cost_test.c, loop0_bad, 3, EXPENSIVE_EXECUTION_TIME_CALL, ERROR, [with estimated cost 1002]

Loading…
Cancel
Save