llvm.org GIT mirror llvm / c2659f1
[CGP] Fix common type handling in optimizeMemoryInst If common type is different we should bail out due to we will not be able to create a select or Phi of these values. Basically it is done in ExtAddrMode::compare however it does not work if we handle the null first and then two values of different types. so add a check in initializeMap as well. The check in ExtAddrMode::compare is used as earlier bail out. Reviewers: reames, john.brawn Reviewed By: john.brawn Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40479 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319292 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 1 year, 11 months ago
2 changed file(s) with 43 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
29082908
29092909 // Build a map between to
29102910 // value of base register.
2911 // Bail out if there is no common type.
29112912 FoldAddrToValueMapping Map;
2912 initializeMap(Map);
2913 if (!initializeMap(Map))
2914 return false;
29132915
29142916 Value *CommonValue = findCommon(Map);
29152917 if (CommonValue)
29232925 /// If address is not an instruction than basic block is set to null.
29242926 /// At the same time we find a common type for different field we will
29252927 /// use to create new Phi/Select nodes. Keep it in CommonType field.
2926 void initializeMap(FoldAddrToValueMapping &Map) {
2928 /// Return false if there is no common type found.
2929 bool initializeMap(FoldAddrToValueMapping &Map) {
29272930 // Keep track of keys where the value is null. We will need to replace it
29282931 // with constant null when we know the common type.
29292932 SmallVector NullValue;
29352938
29362939 Value *DV = AM.GetFieldAsValue(DifferentField, IntPtrTy);
29372940 if (DV) {
2938 if (CommonType)
2939 assert(CommonType == DV->getType() && "Different types detected!");
2940 else
2941 CommonType = DV->getType();
2941 auto *Type = DV->getType();
2942 if (CommonType && CommonType != Type)
2943 return false;
2944 CommonType = Type;
29422945 Map[{ AM.OriginalValue, BB }] = DV;
29432946 } else {
29442947 NullValue.push_back({ AM.OriginalValue, BB });
29472950 assert(CommonType && "At least one non-null value must be!");
29482951 for (auto VIBB : NullValue)
29492952 Map[VIBB] = Constant::getNullValue(CommonType);
2953 return true;
29502954 }
29512955
29522956 /// \brief We have mapping between value A and basic block where value A
507507 %v = add i32 %v1, %v2
508508 ret i32 %v
509509 }
510
511 ; Different types but null is the first?
512 define i32 @test19(i1 %cond1, i1 %cond2, i64* %b2, i8* %b1) {
513 ; CHECK-LABEL: @test19
514 entry:
515 %g1 = getelementptr inbounds i64, i64* %b2, i64 5
516 %bc1 = bitcast i64* %g1 to i32*
517 br i1 %cond1, label %if.then1, label %if.then2
518
519 if.then1:
520 %g2 = getelementptr inbounds i8, i8* %b1, i64 40
521 %bc2 = bitcast i8* %g2 to i32*
522 br label %fallthrough
523
524 if.then2:
525 %bc1_1 = bitcast i64* %g1 to i32*
526 br i1 %cond2, label %fallthrough, label %if.then3
527
528 if.then3:
529 %g3 = getelementptr inbounds i64, i64* null, i64 5
530 %bc1_2 = bitcast i64* %g3 to i32*
531 br label %fallthrough
532
533 fallthrough:
534 ; CHECK-NOT: sunk_phi
535 %c = phi i32* [%bc2, %if.then1], [%bc1_1, %if.then2], [%bc1_2, %if.then3]
536 %v1 = load i32, i32* %c, align 4
537 %g1_1 = getelementptr inbounds i64, i64* %b2, i64 5
538 %bc1_1_1 = bitcast i64* %g1_1 to i32*
539 %v2 = load i32, i32* %bc1_1_1, align 4
540 %v = add i32 %v1, %v2
541 ret i32 %v
542 }