llvm.org GIT mirror llvm / d0592d3
fix PR5930, allowing the asmprinter to emit difference between two labels as a truncate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92455 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
2 changed file(s) with 37 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
818818 const TargetData *TD = TM.getTargetData();
819819 unsigned Opcode = CE->getOpcode();
820820 switch (Opcode) {
821 case Instruction::Trunc:
822821 case Instruction::ZExt:
823822 case Instruction::SExt:
824823 case Instruction::FPTrunc:
864863 return EmitConstantValueOnly(Op);
865864 }
866865
867
868866 case Instruction::PtrToInt: {
869867 // Support only foldable casts to/from pointers that can be eliminated by
870868 // changing the pointer to the appropriately sized integer type.
886884 O << ") & " << S.str() << ')';
887885 break;
888886 }
887
888 case Instruction::Trunc:
889 // We emit the value and depend on the assembler to truncate the generated
890 // expression properly. This is important for differences between
891 // blockaddress labels. Since the two labels are in the same function, it
892 // is reasonable to treat their delta as a 32-bit value.
893 return EmitConstantValueOnly(CE->getOperand(0));
894
889895 case Instruction::Add:
890896 case Instruction::Sub:
891897 case Instruction::And:
1313 ret i8 2
1414 }
1515
16
17 ; PR5930 - Trunc of block address differences.
18 @test.array = internal constant [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint (i8* blockaddress(@test2, %foo) to i64), i64 ptrtoint (i8* blockaddress(@test2, %foo) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (i8* blockaddress(@test2, %bar) to i64), i64 ptrtoint (i8* blockaddress(@test2, %foo) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (i8* blockaddress(@test2, %hack) to i64), i64 ptrtoint (i8* blockaddress(@test2, %foo) to i64)) to i32)] ; <[3 x i32]*> [#uses=1]
19
20 define void @test2(i32 %i) nounwind ssp {
21 entry:
22 %i.addr = alloca i32 ; [#uses=2]
23 store i32 %i, i32* %i.addr
24 %tmp = load i32* %i.addr ; [#uses=1]
25 %idxprom = sext i32 %tmp to i64 ; [#uses=1]
26 %arrayidx = getelementptr inbounds i32* getelementptr inbounds ([3 x i32]* @test.array, i32 0, i32 0), i64 %idxprom ; [#uses=1]
27 %tmp1 = load i32* %arrayidx ; [#uses=1]
28 %idx.ext = sext i32 %tmp1 to i64 ; [#uses=1]
29 %add.ptr = getelementptr i8* blockaddress(@test2, %foo), i64 %idx.ext ; [#uses=1]
30 br label %indirectgoto
31
32 foo: ; preds = %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto, %indirectgoto
33 br label %bar
34
35 bar: ; preds = %foo, %indirectgoto
36 br label %hack
37
38 hack: ; preds = %bar, %indirectgoto
39 ret void
40
41 indirectgoto: ; preds = %entry
42 %indirect.goto.dest = phi i8* [ %add.ptr, %entry ] ; [#uses=1]
43 indirectbr i8* %indirect.goto.dest, [label %foo, label %foo, label %bar, label %foo, label %hack, label %foo, label %foo]
44 }