Who is this for?

This is an introductory topic for C developers who are interested in software optimization

What will you learn?

Upon completion of this Learning Path, you will be able to:

  • Learn the importance of using the `restrict` keyword in C correctly

Prerequisites

Before starting, you will need the following:

  • An Arm computer running Linux OS and a recent version of compiler (Clang or GCC) installed

Summary

AI-assisted

This summary was drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
You’ll use the C99 restrict qualifier to describe non-overlapping pointer regions and enable compiler vectorization on Arm. First, you’ll examine how aliasing inhibits optimization. Then, you’ll add restrict where its contract is safe and inspect the generated assembly. The examples highlight SVE2 code for a byte-processing loop on Armv9-A. You’ll use the examples to recognize when restrict is valid or unsafe.

Frequently asked questions

AI-assisted

These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
How do I know if I can mark these pointers as `restrict`?
Use restrict when the memory regions referenced by the pointer parameters don’t overlap and the function has no other access path to those regions. If any argument can alias another, don’t use restrict.
What result should I expect after I add `restrict` to a loop?
The compiler can assume no aliasing and might generate vectorized code. On Arm with SVE2, look for vector registers (z0z31) and predicated operations in the assembly.
How do I spot an overlap that would invalidate my use of `restrict`?
If one pointer argument derives from another, such as a pointer into the same array, the regions overlap. Passing those pointers to a restrict-qualified function violates its contract.
Where do I check that the compiler used SVE2 for my example?
Inspect the generated assembly for SVE2 instructions and vector registers. whilelo predicates and ld1b or st1b instructions with z registers indicate SVE2 code generation.
When should I avoid using `restrict` even if pointers look independent?
Avoid restrict if the function can reach the same memory through another alias, such as a global pointer or indirect access. The non-aliasing guarantee must hold throughout the function.
Next