<div dir="ltr">I would argue that unless you've benchmarked a piece of code found this to be a problem, then writing code with the express purpose of having it be more optimizable at the expense of readability and ease of understanding is a classic example of premature optimization. And if you have, then you can used signed integers in that specific piece of code, and leave a comment about why it should not be changed.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 11, 2019 at 9:59 AM David Greene via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">James Henderson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> writes:<br>
<br>
> Maybe it's just because I work in code around the binary file formats<br>
> almost exclusively, but unsigned (or more often uint64_t) is FAR more<br>
> common than int everywhere I go. I don't have time right now to read<br>
> up on the different links you provided, and I expect this is covered<br>
> in them, but it also seems odd to me to use int in a loop when<br>
> indexing in a container (something that can't always be avoided),<br>
> given the types of size() etc.<br>
<br>
The reason to use int as an index in loops is for its algebraic<br>
properties, which allows some optimizations (vectorization, for<br>
example), where unsigned would cause problems.<br>
<br>
Basically, the optimizer can assume overflow is undefined behavior and<br>
optimize accordingly.<br>
<br>
+10000 for preferring signed unless there's a good reason for unsigned.<br>
<br>
-David<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>