Keil Logo

NOALIAS Compiler Directive

Abbreviation

NOAL

Arguments

None.

Default

All write operations via pointer are destructive. The compiler does not reuse the contents of registers when variables are accessed through pointers.

µVision

Options — CA — Alias Checking on Pointer Accesses.

Description

It is common practice for the compiler to copy a variable's value into a register for fast, temporary access. However, when the value is changed through a pointer to the variable, the contents of the register must be re-synchronized. The technique which does this is known as alias checking. It is enabled by default.

The NOALIAS directive instructs the compiler to ignore pointer write operations during the optimization phase. If a register holds a variable, the variable is reused, even when access through a pointer might have modified that variable.

If you are confident that certain functions in your program do not modify variables through pointers, the NOALIAS directive may be used to reduce program size.

Example
CA SAMPLE.C NOALIAS

#pragma NOAL

The following example:

 stmt  level    source
    1          struct { int  i1; int  i2; } *p_struct;
    2          int val;
    3
    4          void func1 (int *p_val)  {
    5   1        p_struct->i1 = val;
    6   1        *p_val = 0;
    7   1        p_struct->i2 = val;
    8   1      }
    9
   10          void func2 (void)  {
   11   1        func1 (&val);
   12   1      }

demonstrates code generated using the NOALIAS directive:

Code Generated
Without NOALIAS
*** CODE SEGMENT '?PR?func1?T?noalias':
    4: void func1 (int *p_val)  {
 00000000  ---- 'p_val' assigned to 'R0' ----
    5:   p_struct->i1 = val;
 00000000  4800  LDR  R1,=val ; val
 00000002  680A  LDR  R2,[R1,#0x0] ; val
 00000004  4800  LDR  R1,=p_struct ; p_struct
 00000006  6809  LDR  R1,[R1,#0x0] ; p_struct
 00000008  600A  STR  R2,[R1,#0x0]
    6:   *p_val = 0;
 0000000A  2100  MOV  R1,#0x0
 0000000C  6001  STR  R1,[R0,#0x0] ; p_val
    7:   p_struct->i2 = val;
 0000000E  4800  LDR  R0,=val ; val
 00000010  6800  LDR  R0,[R0,#0x0] ; val
 00000012  4800  LDR  R1,=p_struct ; p_struct
 00000014  6809  LDR  R1,[R1,#0x0] ; p_struct
 00000016  6048  STR  R0,[R1,#0x4]
    8: }
 00000018  4770  BX          R14
 0000001A          ENDP ; 'func1?T'


*** CODE SEGMENT '?PR?func2?T?noalias':
   10: void func2 (void)  {
 00000000  B500  PUSH        {LR}
   11:   func1 (&val);
 00000002  4800  LDR  R0,=val ; val
 00000004  F7FF  BL   func1?T  ; T=0x0001  (1)
 00000006  FFFC  BL   func1?T  ; T=0x0001  (2)
 0000000A  BC08  POP  {R3}
 0000000C  4718  BX   R3
 0000000E          ENDP ; 'func2?T'
CODE SIZE: 40 Bytes
Code Generated
With NOALIAS
*** CODE SEGMENT '?PR?func1?T?noalias':
    4: void func1 (int *p_val)  {
 00000000  ---- 'p_val' assigned to 'R0' ----
    5:   p_struct->i1 = val;
 00000000  4800  LDR  R1,=val ; val
 00000002  680A  LDR  R2,[R1,#0x0] ; val
 00000004  4800  LDR  R1,=p_struct ; p_struct
 00000006  6809  LDR  R1,[R1,#0x0] ; p_struct
 00000008  600A  STR  R2,[R1,#0x0]
    6:   *p_val = 0;
 0000000A  2200  MOV  R2,#0x0
 0000000C  6002  STR  R2,[R0,#0x0] ; p_val
    7:   p_struct->i2 = val;
 0000000E  4800  LDR  R0,=val ; val
 00000010  6800  LDR  R0,[R0,#0x0] ; val


 00000012  6048  STR  R0,[R1,#0x4]
    8: }
 00000014  4770  BX   R14
 00000016          ENDP ; 'func1?T'


*** CODE SEGMENT '?PR?func2?T?noalias':
   10: void func2 (void)  {
 00000000  B500  PUSH        {LR}
   11:   func1 (&val);
 00000002  4800  LDR  R0,=val ; val
 00000004  F7FF  BL   func1?T  ; T=0x0001  (1)
 00000006  FFFC  BL   func1?T  ; T=0x0001  (2)
 0000000A  BC08  POP  {R3}
 0000000C  4718  BX   R3
 0000000E          ENDP ; 'func2?T'
CODE SIZE: 36 Bytes

When the NOALIAS directive is used, the compiler does not reload p_struct or val, even though the *p_val = 0 statement destroys val.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.