llvm.org GIT mirror llvm / fcce259
For PR9500. --- Merging r128041 into '.': U test/CodeGen/X86/fast-isel-gep.ll U lib/Target/X86/X86FastISel.cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_29@128042 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
2 changed file(s) with 41 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
398398 Disp += SL->getElementOffset(Idx);
399399 } else {
400400 uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType());
401 SmallVector Worklist;
402 Worklist.push_back(Op);
403 do {
404 Op = Worklist.pop_back_val();
401 for (;;) {
405402 if (const ConstantInt *CI = dyn_cast(Op)) {
406403 // Constant-offset addressing.
407404 Disp += CI->getSExtValue() * S;
408 } else if (isa(Op) &&
409 isa(cast(Op)->getOperand(1))) {
410 // An add with a constant operand. Fold the constant.
405 break;
406 }
407 if (isa(Op) &&
408 (!isa(Op) ||
409 FuncInfo.MBBMap[cast(Op)->getParent()]
410 == FuncInfo.MBB) &&
411 isa(cast(Op)->getOperand(1))) {
412 // An add (in the same block) with a constant operand. Fold the
413 // constant.
411414 ConstantInt *CI =
412415 cast(cast(Op)->getOperand(1));
413416 Disp += CI->getSExtValue() * S;
414 // Add the other operand back to the work list.
415 Worklist.push_back(cast(Op)->getOperand(0));
416 } else if (IndexReg == 0 &&
417 (!AM.GV || !Subtarget->isPICStyleRIPRel()) &&
418 (S == 1 || S == 2 || S == 4 || S == 8)) {
417 // Iterate on the other operand.
418 Op = cast(Op)->getOperand(0);
419 continue;
420 }
421 if (IndexReg == 0 &&
422 (!AM.GV || !Subtarget->isPICStyleRIPRel()) &&
423 (S == 1 || S == 2 || S == 4 || S == 8)) {
419424 // Scaled-index addressing.
420425 Scale = S;
421426 IndexReg = getRegForGEPIndex(Op).first;
422427 if (IndexReg == 0)
423428 return false;
424 } else
425 // Unsupported.
426 goto unsupported_gep;
427 } while (!Worklist.empty());
429 break;
430 }
431 // Unsupported.
432 goto unsupported_gep;
433 }
428434 }
429435 }
430436 // Check for displacement overflow.
8686 ; X64-NEXT: ret
8787 }
8888
89 ; PR9500, rdar://9156159 - Don't do non-local address mode folding,
90 ; because it may require values which wouldn't otherwise be live out
91 ; of their blocks.
92 define void @test6() {
93 if.end: ; preds = %if.then, %invoke.cont
94 %tmp15 = load i64* undef
95 %dec = add i64 %tmp15, 13
96 store i64 %dec, i64* undef
97 %call17 = invoke i8* @_ZNK18G__FastAllocString4dataEv()
98 to label %invoke.cont16 unwind label %lpad
8999
100 invoke.cont16: ; preds = %if.then14
101 %arrayidx18 = getelementptr inbounds i8* %call17, i64 %dec
102 store i8 0, i8* %arrayidx18
103 unreachable
104
105 lpad: ; preds = %if.end19, %if.then14, %if.end, %entry
106 unreachable
107 }
108 declare i8* @_ZNK18G__FastAllocString4dataEv() nounwind