This is an archive of the discontinued LLVM Phabricator instance.

instruction 'align' in asm blocks works incorrectly with some cases of parameters clean revision
ClosedPublic

Authored by m_zuckerman on Oct 27 2015, 7:42 AM.

Details

Summary

This is a clean revision:
The old revision is http://reviews.llvm.org/D13869#inline-115174
This align directive doesn't work on the -fasm-blocks.

ALIGN [[number]]
Aligns the next variable or instruction on a byte that is a multiple of number.

Microsoft support only power of 2 align like gcc and icc .
The problem with the code was in the AsmParser.cpp
Inside the AsmParser::parseDirectiveMSAlign function we trying to lowering number in to log of two. This is not correct and not consistent with Microsoft compilers.
**CASE 1: Microsoft compatibility
align should work only with address of multiply of two.

int f(void)
 {
__asm { align 2 }
__asm { align 4 }
__asm { align 8 }
__asm { align 16 }
__asm { align 32 }
return 0;


}

int main()
 {
return f();
}

CASE 2: Darwin compatibility
Incorrect lowering inline asm with -fasm-blocks for Darwin.

int f(void)
{
    asm { align 2 }
    asm { align 4 }
 
    return 0;
}

Output

## InlineAsm Start
.align 1, 0x90
## InlineAsm End
mov dword ptr [esp], eax

## InlineAsm Start
.align 2, 0x90
## InlineAsm End

It's should be

## InlineAsm Start
.align 2, 0x90
## InlineAsm End
mov dword ptr [esp], eax

## InlineAsm Start
.align 4, 0x90
## InlineAsm End

For not log2 number like align 3 error retrieve.

Diff Detail

Repository
rL LLVM

Event Timeline

m_zuckerman retitled this revision from to instruction 'align' in asm blocks works incorrectly with some cases of parameters.
m_zuckerman updated this object.
m_zuckerman updated this object.
m_zuckerman retitled this revision from instruction 'align' in asm blocks works incorrectly with some cases of parameters to instruction 'align' in asm blocks works incorrectly with some cases of parameters clean revision.
m_zuckerman updated this object.
m_zuckerman added inline comments.Oct 27 2015, 7:57 AM
lib/MC/MCParser/AsmParser.cpp
4509 ↗(On Diff #38546)

Add check for only In bytes mode for the number is actually log 2 of the number.

4513 ↗(On Diff #38546)

Only need to rewrite the align N to .align N
In all OS.
Only Microsoft was lowering the align N to .align log2(N) in the past.
Now all OS lowering the align N to .align N

4679 ↗(On Diff #38546)

Not need additional skip because no new value are pass.

4715–4716 ↗(On Diff #38546)

There is no new val.

4718–4720 ↗(On Diff #38546)

This was relevant when Microsoft lower the align N to .align log2N

test/CodeGen/ms-inline-asm.c
294–299 ↗(On Diff #38546)

Incorrect lowering of the align N for Darwin The running mode is
// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fasm-blocks -emit-llvm -o - | FileCheck %s

rnk added inline comments.Oct 27 2015, 9:39 AM
test/CodeGen/ms-inline-asm.c
294–299 ↗(On Diff #38546)

I don't think this is incorrect. This appears to be our fundamental disagreement. Please review my comments from earlier about how this should work.

This revision was automatically updated to reflect the committed changes.