llvm.org GIT mirror llvm / 7c4efa6
When InstCombine simplifies a load -> extract element to gep -> load, place the new load by the old load instead of by the extract element because a store could have occurred between the load and extract element. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78891 91177308-0d34-0410-b5e6-96231b3b80d8 Mon P Wang 10 years ago
2 changed file(s) with 28 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1246412464 unsigned AS =
1246512465 cast(I->getOperand(0)->getType())->getAddressSpace();
1246612466 Value *Ptr = InsertBitCastBefore(I->getOperand(0),
12467 PointerType::get(EI.getType(), AS),EI);
12467 PointerType::get(EI.getType(), AS),*I);
1246812468 GetElementPtrInst *GEP =
1246912469 GetElementPtrInst::Create(Ptr, EI.getOperand(1), I->getName()+".gep");
1247012470 cast(GEP)->setIsInBounds(true);
12471 InsertNewInstBefore(GEP, EI);
12472 return new LoadInst(GEP);
12471 InsertNewInstBefore(GEP, *I);
12472 LoadInst* Load = new LoadInst(GEP, "tmp");
12473 InsertNewInstBefore(Load, *I);
12474 return ReplaceInstUsesWith(EI, Load);
1247312475 }
1247412476 }
1247512477 if (InsertElementInst *IE = dyn_cast(I)) {
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | FileCheck %s
1
2 ; The load replacing the extract element must occur before the call
3 ; that may modify local array a.
4
5 declare void @mod_a_func(<4 x float>* %a);
6
7 ; CHECK: load float* %arraydecay1, align 16
8 ; CHECK: call void @mod_a_func
9
10 define void @cl_jpegenc_k2(<4 x float> addrspace(1)* %src, float addrspace(1)* %dst) {
11 %a = alloca [2 x <4 x float>], align 16
12 %arraydecay = getelementptr [2 x <4 x float>]* %a, i32 0, i32 0
13 %arrayidx31 = getelementptr <4 x float> addrspace(1)* %src, i32 0
14 %tmp32 = load <4 x float> addrspace(1)* %arrayidx31
15 store <4 x float> %tmp32, <4 x float>* %arraydecay, align 16
16 %tmp86 = load <4 x float>* %arraydecay, align 16
17 call void @mod_a_func(<4 x float>* %arraydecay)
18 %arrayidx132 = getelementptr float addrspace(1)* %dst, i32 0
19 %tmp236 = extractelement <4 x float> %tmp86, i32 0
20 store float %tmp236, float addrspace(1)* %arrayidx132
21 ret void
22 }