[LLVMdev] LLVM Concurrency and Undef

Santosh Nagarakatte santosh.nagarakatte at gmail.com
Mon Aug 22 14:49:51 PDT 2011


Hi all,

I have been trying to understand the use of undef in both sequential
and concurrent programs.

>From the LLVM Language Reference Manual, I see the following
definition of undef.
"Undef can be used anywhere a constant is expected, and indicates that
the user of the value may receive an unspecified bit-pattern".
 LLVM Language Reference manual also demonstrates how optimizers can
use these undef values to  optimize the program.

However, on the other hand, with the LLVM Atomics and Concurrency
Guide states that
If code accesses a memory location from multiple threads at the same
time, the resulting loads return 'undef'.
This is different from the C++ memory model, which provides undefined
behavior. What is the rationale for returning an undef on racing
reads?

LLVM Atomics and Concurrency guide also states the following
"Note that speculative loads are allowed; a load which is part of a
race returns undef, but does not have undefined behavior"

If the speculative loads returns an undef and the returned value is
used, then it results in an undefined behavior. Am I correct?
If so, what is the purpose of returning an undef with a speculative load?
Is it to ensure that the subsequent uses of the value of the
speculatively introduced load is caught/detected by the optimization?

Is it possible to separate the "undef" in a sequential setting and
"undef" with speculative loads in a concurrent setting with separate
undefs?


Thanks,
Santosh


-- 
Santosh G Nagarakatte,
PhD Student,
Computer and Information Science Department
University of Pennsylvania,
Philadelphia-19104
http://www.cis.upenn.edu/~santoshn



More information about the llvm-dev mailing list