Hi Michael,<br><br>I think the complexity comes from the subtraction having as its domain two unsigned integers- so it's range must be a larger signed integer.<br><br>Signed comparison for unsigned values is clearly wrong as you say, but I could contruct a testcase that shows incorrect behaviour with an unsigned comparison too. I think the only correct behaviour is to extend the inputs first and truncate the result. <br><br>But I've been wrong before :)<br><br>James<br><div class="gmail_quote"><div dir="ltr">On Mon, 3 Aug 2015 at 21:05, Michael Zolotukhin <<a href="mailto:mzolotukhin@apple.com">mzolotukhin@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mzolotukhin added inline comments.<br>
<br>
================<br>
Comment at: docs/LangRef.rst:10387-10390<br>
@@ -10386,6 +10386,6 @@<br>
<br>
     %sub = sub nsw <4 x i32> %a, %b<br>
-    %ispos = icmp sgt <4 x i32> %sub, <i32 -1, i32 -1, i32 -1, i32 -1><br>
+    %ispos = icmp sge <4 x i32> %sub, zeroinitializer<br>
     %neg = sub nsw <4 x i32> zeroinitializer, %sub<br>
     %1 = select <4 x i1> %ispos, <4 x i32> %sub, <4 x i32> %neg<br>
<br>
----------------<br>
ashahid wrote:<br>
> mzolotukhin wrote:<br>
> > What's the difference between `llvm.uabsdiff` and `llvm.sabsdiff` then?<br>
> The difference is the presence of NSW flag in case of llvm.sabsdiff.<br>
I still don't think it's correct. NSW is just a hint to optimizers, but it doesn't add any additional logic. It does assert that the expression won't overflow, but the operations we execute are still the same. That is, currently the only difference between signed and unsigned version is that for signed version we could get an undefined behavior in some cases. This is clearly incorrect, because we should get different results without undefined behavior in some cases (e.g. `<-1,-1,-1,-1>` and `<1,1,1,1>` - it should give `<254,254,254,254>` for `uabsdiff.v4i8` and `<2,2,2,2>` for `sabsdiff.v4i8`).<br>
<br>
What really should be the difference, as far is I understand, is condition code in the comparison:<br>
```<br>
%ispos = icmp sge <4 x i32> %sub, zeroinitializer<br>
```<br>
As far as I understand, we should use `uge` for unsigned and `sge` for signed case.<br>
<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11678&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=D3aEYuw5A_n689rOCqkFe1DIxDtvtfhFchEhn071mZM&s=o6zIcwKHl1wG46sIczguZFjO_LQ1iurVrYNb-VOUTFo&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D11678</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>