llvm.org GIT mirror llvm / 9ae59e3
SimplifyCFG: GEPs with just one non-constant index are also cheap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126452 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
2 changed file(s) with 27 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
246246 if (PBB->getFirstNonPHIOrDbg() != I)
247247 return false;
248248 break;
249 case Instruction::GetElementPtr:
250 // GEPs are cheap if all indices are constant.
251 if (!cast(I)->hasAllConstantIndices())
249 case Instruction::GetElementPtr: {
250 // GEPs are cheap if all indices are constant or if there's only one index.
251 GetElementPtrInst *GEP = cast(I);
252 if (!GEP->hasAllConstantIndices() && GEP->getNumIndices() > 1)
252253 return false;
253254 break;
255 }
254256 case Instruction::Add:
255257 case Instruction::Sub:
256258 case Instruction::And:
0 ; RUN: opt -S -simplifycfg %s | FileCheck %s
11
2 define i8* @test1(i8* %x) nounwind {
2 define i8* @test1(i8* %x, i64 %y) nounwind {
33 entry:
44 %tmp1 = load i8* %x, align 1
55 %cmp = icmp eq i8 %tmp1, 47
66 br i1 %cmp, label %if.then, label %if.end
77
88 if.then:
9 %incdec.ptr = getelementptr inbounds i8* %x, i64 1
9 %incdec.ptr = getelementptr inbounds i8* %x, i64 %y
1010 br label %if.end
1111
1212 if.end:
1717 ; CHECK: %x.addr = select i1 %cmp, i8* %incdec.ptr, i8* %x
1818 ; CHECK: ret i8* %x.addr
1919 }
20
21 %ST = type { i8, i8 }
22
23 define i8* @test2(%ST* %x, i8* %y) nounwind {
24 entry:
25 %cmp = icmp eq %ST* %x, null
26 br i1 %cmp, label %if.then, label %if.end
27
28 if.then:
29 %incdec.ptr = getelementptr %ST* %x, i32 0, i32 1
30 br label %if.end
31
32 if.end:
33 %x.addr = phi i8* [ %incdec.ptr, %if.then ], [ %y, %entry ]
34 ret i8* %x.addr
35
36 ; CHECK: @test2
37 ; CHECK: %x.addr = select i1 %cmp, i8* %incdec.ptr, i8* %y
38 ; CHECK: ret i8* %x.addr
39 }