<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102823>102823</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[IR] A question about the ordering of allocas
</td>
</tr>
<tr>
<th>Labels</th>
<td>
question,
documentation,
llvm:ir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
See the following stack growth direction detection idiom: https://github.com/google/googletest/blob/ff233bdd4cac0a0bf6e5cd45bda3406814cb2796/googletest/src/gtest-death-test.cc#L1213-L1247
LLVM IR for `testing::internal::StackGrowsDown()`:
```
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define hidden noundef zeroext i1 @_ZN7testing8internal14StackGrowsDownEv() local_unnamed_addr #4 {
entry:
%dummy.i = alloca i32, align 4
%dummy = alloca i32, align 4
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %dummy.i)
%cmp.i = icmp ult ptr %dummy.i, %dummy
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %dummy.i)
ret i1 %cmp.i
}
```
Is it a well-defined behavior? If we swap these two allocas, does it produce the opposite result? If so, are we allowed to constant fold the pointer comparison based on `TargetFrameLowering::getStackGrowthDirection`?
I cannot find any information from LangRef.
cc @RKSimon @topperc @nikic
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVEtv4zYQ_jX0ZWBDIiXLPujgrOsiqNtDUvTQS0CRI5ldiqOSVLTeX19QcrzJougDMGjOaB7fx3nIEEznEGtWPrDyuJJjvJCvdVRfvl6nVUP6Wj8jQrwgtGQtTcZ1EKJUn6HzNMULaONRRUMONMbbzWhDPRMHuMQ4BCYOjJ8YP3UmXsZmo6hPAlFn8X6JGCLjp8ZSw_ipbbkQjdaFkiqTWdNusVS6KBstRZFtd3mhGl7tt9-7B6-SKklrjTJe1um6UYpxcc55LtbnnBcVy44sOy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