diff options
author | Patrik Hagglund <patrik.h.hagglund@ericsson.com> | 2016-06-20 10:19:00 +0000 |
---|---|---|
committer | Patrik Hagglund <patrik.h.hagglund@ericsson.com> | 2016-06-20 10:19:00 +0000 |
commit | a83706e354705188606bbb857a4d6703c3284d1c (patch) | |
tree | 88cf43876f426ba7e1989c4e4a1faa3b4cb55538 /llvm/lib | |
parent | c31fee22122c0b7546a8f853252456402a226253 (diff) | |
download | bcm5719-llvm-a83706e354705188606bbb857a4d6703c3284d1c.tar.gz bcm5719-llvm-a83706e354705188606bbb857a4d6703c3284d1c.zip |
Avoid output indeterminism between GCC and Clang builds.
Remove dependency of the evalution order of function arguments, which
is unspecified.
The following test previously failed when built with GCC (but succeded
when built with Clang):
; RUN: opt -sroa -S < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%A = type {i16}
@a = global %A* null
@b = global i16 0
; CHECK-LABEL: @f1(
; CHECK: alloca %A
; CHECK-NEXT: extractvalue %A
; CHECK-NEXT: getelementptr inbounds %A
define void @f1 (%A %a) {
%1 = alloca %A
store %A %a, %A* %1
%2 = load i16, i16* @b
%3 = icmp ne i16 %2, 0
br i1 %3, label %bb1, label %bb2
bb1:
store %A* %1, %A** @a
br label %bb2
bb2:
ret void
}
Patch by David Stenberg.
Differential Revision: http://reviews.llvm.org/D21226
llvm-svn: 273144
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/SROA.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index cbe36861a67..830b23c4bff 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -3107,9 +3107,14 @@ private: void emitFunc(Type *Ty, Value *&Agg, const Twine &Name) { assert(Ty->isSingleValueType()); // Extract the single value and store it using the indices. - Value *Store = IRB.CreateStore( - IRB.CreateExtractValue(Agg, Indices, Name + ".extract"), - IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep")); + // + // The gep and extractvalue values are factored out of the CreateStore + // call to make the output independent of the argument evaluation order. + Value *ExtractValue = IRB.CreateExtractValue(Agg, Indices, + Name + ".extract"); + Value *InBoundsGEP = IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, + Name + ".gep"); + Value *Store = IRB.CreateStore(ExtractValue, InBoundsGEP); (void)Store; DEBUG(dbgs() << " to: " << *Store << "\n"); } |