kasuga-fj wrote:

> APInt has several routines that deal determine overflow, e.g. sadd_ov, 
> ssub_ov, etc. So, as a very minimum, if we need a convenience wrapper, we 
> should first use those routines?

This is exactly a wrapper for those routines. I defined the wrapper for 
readability. For example, we have the following piece of code which may 
overflow:

```cpp
LowerDistance = (TY - TX) + (TA - TB) * TL;
```

If we use `sadd_ov`, `ssub_ov` and `smul_ov` directly, the code will become:

```cpp
bool Overflow;
APInt Tmp0 = TY.ssub_ov(TX, Overflow);
if (Overflow) ...;
APInt Tmp1 = TA.ssub_ov(TB, Overflow);
if (Overflow) ...;
APInt Tmp2 = Tmp1.smul_ov(TL, Overflow);
if (Overflow) ...;
LowerDistance = Tmp0.sadd_ov(Tmp2, Overflow);
if (Overflow) ...;
```

I think it's a bit ugly and hard to read/maintain. Using a wrapper allows us to 
keep the code clean and readable.

https://github.com/llvm/llvm-project/pull/171991
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to