[cfe-dev] Disable integer promotion (Dilan Manatunga via cfe-dev)

David Majnemer via cfe-dev cfe-dev at lists.llvm.org
Fri May 27 11:55:02 PDT 2016


You could set IntWidth to 16 or 8 in clang, not unlike what MSP430 does:
https://github.com/llvm-mirror/clang/blob/3317d0fa0bd1f5c5adc14bcc6adc2a38acc9064b/lib/Basic/Targets.cpp#L6823

On Fri, May 27, 2016 at 10:32 AM, Dilan Manatunga via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> I need disabling this feature because I am researching architectures where
> 8-bit or 16-bit adds are preferred to 32-bit. So, integer promotion kinda
> mucks everything up. I was hoping there was a way in clang to disable it,
> instead of having to implement an LLVM pass to coalesce unnecessary
> promotions.
>
> Thanks for catching the IR mistake. Should have double checked that. This
> should be the correct version:
> nt8_t a  = 1;
> int8_t b = 2;
> int8_t c = a + b
>
> The LLVM IR will be:
> %x = sext i8 %a to i32
> %y = sext i8 %b to i32
> %z = add nsw i32 %x, %y
> %c = trunc i32 %z to i8
>
> Instead, it would simply compile to:
> $c = add nsw i8 %z, $y
>
> -Dilan
>
>
> On Fri, May 27, 2016 at 5:30 AM Norman Rink via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> Hi Dilan,
>>
>> I would like to second your request for an option to disable integer
>> promotion. What do you need it for?
>>
>> As far as I am aware, there is no such option and the code that implements
>> integer promotion is somewhat scattered across ³SemaExpr.cpp².
>>
>> Also, I think your example code snippet contains a few ³i32²s too many. It
>> will be clearer to people what you are looking for if your code example is
>> consistent with your question.
>>
>> Best,
>>
>> Norman
>>
>>
>> >Message: 1
>> >Date: Fri, 27 May 2016 01:50:12 +0000
>> >From: Dilan Manatunga via cfe-dev <cfe-dev at lists.llvm.org>
>> >To: cfe-dev at lists.llvm.org
>> >Subject: [cfe-dev] Disable integer promotion
>> >Message-ID:
>> >       <CAHpgGu4=
>> jFC9ohQQZZMp2NMG3Hw0sE5U4-Lqrgb+6gcXv9SEtQ at mail.gmail.com>
>> >Content-Type: text/plain; charset="utf-8"
>> >
>> >Is there a way to disable integer promotion when performing math
>> >operations. For example, when compiling a statement such as this:
>> >int8_t a  = 1;
>> >int8_t b = 2;
>> >int8_t c = a + b
>> >
>> >The LLVM IR will be:
>> >%x = sext i32 %a to i32
>> >%y = sext i32 %b to i32
>> >%z = add nsw i32 %x, %y
>> >%c = trunc i32 %z to i16
>> >
>> >Instead, it would simply compile to:
>> >$c = add nsw i32 %z, $y
>> >
>> >-Dilan Manatunga
>> >-------------- next part --------------
>> >An HTML attachment was scrubbed...
>> >URL:
>> ><
>> http://lists.llvm.org/pipermail/cfe-dev/attachments/20160527/4a7920ab/att
>> >achment-0001.html>
>> >
>> >------------------------------
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160527/94378838/attachment.html>


More information about the cfe-dev mailing list