llvm.org GIT mirror llvm / 43ee5f7
Add a new Constant::getIntegerValue helper function, and convert a few places in InstCombine to use it, to fix problems handling pointer types. This fixes the recent llvm-gcc bootstrap error. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78005 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
4 changed file(s) with 111 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1616 #include "llvm/User.h"
1717
1818 namespace llvm {
19 class APInt;
20
1921 template class SmallVectorImpl;
2022 class LLVMContext;
2123
141143 /// its bits set to true.
142144 /// @brief Get the all ones value
143145 static Constant* getAllOnesValue(const Type* Ty);
146
147 /// getIntegerValue - Return the value for an integer or pointer constant,
148 /// or a vector thereof, with the given scalar value.
149 static Constant* getIntegerValue(const Type* Ty, const APInt &V);
144150 };
145151
146152 } // End llvm namespace
10131013 if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
10141014 // all known
10151015 if ((RHSKnownOne & LHSKnownOne) == RHSKnownOne) {
1016 Constant *AndC = ConstantInt::get(VTy,
1017 ~RHSKnownOne & DemandedMask);
1016 Constant *AndC = Constant::getIntegerValue(VTy,
1017 ~RHSKnownOne & DemandedMask);
10181018 Instruction *And =
10191019 BinaryOperator::CreateAnd(I->getOperand(0), AndC, "tmp");
10201020 return InsertNewInstBefore(And, *I);
14051405
14061406 // If the client is only demanding bits that we know, return the known
14071407 // constant.
1408 if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
1409 Constant *C = ConstantInt::get(VTy, RHSKnownOne);
1410 if (isa(V->getType()))
1411 C = ConstantExpr::getIntToPtr(C, V->getType());
1412 return C;
1413 }
1408 if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask)
1409 return Constant::getIntegerValue(VTy, RHSKnownOne);
14141410 return false;
14151411 }
14161412
6767 assert(!"Cannot create a null constant of that type!");
6868 return 0;
6969 }
70 }
71
72 Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) {
73 const Type *ScalarTy = Ty->getScalarType();
74
75 // Create the base integer constant.
76 Constant *C = ConstantInt::get(Ty->getContext(), V);
77
78 // Convert an integer to a pointer, if necessary.
79 if (const PointerType *PTy = dyn_cast(ScalarTy))
80 C = ConstantExpr::getIntToPtr(C, PTy);
81
82 // Broadcast a scalar to a vector, if necessary.
83 if (const VectorType *VTy = dyn_cast(Ty))
84 C = ConstantVector::get(std::vector(VTy->getNumElements(), C));
85
86 return C;
7087 }
7188
7289 Constant* Constant::getAllOnesValue(const Type* Ty) {
0 ; RUN: llvm-as < %s | opt -instcombine
1
2 ; SimplifyDemandedBits should cope with pointer types.
3
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
5 target triple = "x86_64-unknown-linux-gnu"
6 %struct.VEC_rtx_base = type { i32, i32, [1 x %struct.rtx_def*] }
7 %struct.VEC_rtx_gc = type { %struct.VEC_rtx_base }
8 %struct.block_symbol = type { [3 x %struct.rtunion], %struct.object_block*, i64 }
9 %struct.object_block = type { %struct.section*, i32, i64, %struct.VEC_rtx_gc*, %struct.VEC_rtx_gc* }
10 %struct.omp_clause_subcode = type { i32 }
11 %struct.rtunion = type { i8* }
12 %struct.rtx_def = type { i16, i8, i8, %struct.u }
13 %struct.section = type { %struct.unnamed_section }
14 %struct.u = type { %struct.block_symbol }
15 %struct.unnamed_section = type { %struct.omp_clause_subcode, void (i8*)*, i8*, %struct.section* }
16
17 define fastcc void @cse_insn(%struct.rtx_def* %insn, %struct.rtx_def* %libcall_insn) nounwind {
18 entry:
19 br i1 undef, label %bb43, label %bb88
20
21 bb43: ; preds = %entry
22 br label %bb88
23
24 bb88: ; preds = %bb43, %entry
25 br i1 undef, label %bb95, label %bb107
26
27 bb95: ; preds = %bb88
28 unreachable
29
30 bb107: ; preds = %bb88
31 %0 = load i16* undef, align 8 ; [#uses=1]
32 %1 = icmp eq i16 %0, 38 ; [#uses=1]
33 %src_eqv_here.0 = select i1 %1, %struct.rtx_def* null, %struct.rtx_def* null ; <%struct.rtx_def*> [#uses=1]
34 br i1 undef, label %bb127, label %bb125
35
36 bb125: ; preds = %bb107
37 br i1 undef, label %bb127, label %bb126
38
39 bb126: ; preds = %bb125
40 br i1 undef, label %bb129, label %bb133
41
42 bb127: ; preds = %bb125, %bb107
43 unreachable
44
45 bb129: ; preds = %bb126
46 br label %bb133
47
48 bb133: ; preds = %bb129, %bb126
49 br i1 undef, label %bb134, label %bb146
50
51 bb134: ; preds = %bb133
52 unreachable
53
54 bb146: ; preds = %bb133
55 br i1 undef, label %bb180, label %bb186
56
57 bb180: ; preds = %bb146
58 %2 = icmp eq %struct.rtx_def* null, null ; [#uses=1]
59 %3 = zext i1 %2 to i8 ; [#uses=1]
60 %4 = icmp ne %struct.rtx_def* %src_eqv_here.0, null ; [#uses=1]
61 %5 = zext i1 %4 to i8 ; [#uses=1]
62 %toBool181 = icmp ne i8 %3, 0 ; [#uses=1]
63 %toBool182 = icmp ne i8 %5, 0 ; [#uses=1]
64 %6 = and i1 %toBool181, %toBool182 ; [#uses=1]
65 %7 = zext i1 %6 to i8 ; [#uses=1]
66 %toBool183 = icmp ne i8 %7, 0 ; [#uses=1]
67 br i1 %toBool183, label %bb184, label %bb186
68
69 bb184: ; preds = %bb180
70 br i1 undef, label %bb185, label %bb186
71
72 bb185: ; preds = %bb184
73 br label %bb186
74
75 bb186: ; preds = %bb185, %bb184, %bb180, %bb146
76 br i1 undef, label %bb190, label %bb195
77
78 bb190: ; preds = %bb186
79 unreachable
80
81 bb195: ; preds = %bb186
82 unreachable
83 }