Eliminate ConstantBool::True and ConstantBool::False. Instead, provide

ConstantBool::getTrue() and ConstantBool::getFalse().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30665 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-09-28 23:35:22 +00:00
parent 850ba99cb6
commit 47811b76ca
11 changed files with 2983 additions and 3981 deletions

View File

@ -172,8 +172,8 @@ struct ValID {
case ConstUIntVal :
case ConstSIntVal : return std::string("%") + itostr(ConstPool64);
case ConstantVal:
if (ConstantValue == ConstantBool::True) return "true";
if (ConstantValue == ConstantBool::False) return "false";
if (ConstantValue == ConstantBool::getTrue()) return "true";
if (ConstantValue == ConstantBool::getFalse()) return "false";
return "<constant expression>";
default:
assert(0 && "Unknown value!");

File diff suppressed because it is too large Load Diff

View File

@ -1,254 +1,4 @@
/* A Bison parser, made by GNU Bison 2.1. */
/* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* As a special exception, when this file is copied by Bison into a
Bison output file, you may use that output file without restriction.
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
ESINT64VAL = 258,
EUINT64VAL = 259,
SINTVAL = 260,
UINTVAL = 261,
FPVAL = 262,
VOID = 263,
BOOL = 264,
SBYTE = 265,
UBYTE = 266,
SHORT = 267,
USHORT = 268,
INT = 269,
UINT = 270,
LONG = 271,
ULONG = 272,
FLOAT = 273,
DOUBLE = 274,
TYPE = 275,
LABEL = 276,
VAR_ID = 277,
LABELSTR = 278,
STRINGCONSTANT = 279,
IMPLEMENTATION = 280,
ZEROINITIALIZER = 281,
TRUETOK = 282,
FALSETOK = 283,
BEGINTOK = 284,
ENDTOK = 285,
DECLARE = 286,
GLOBAL = 287,
CONSTANT = 288,
SECTION = 289,
VOLATILE = 290,
TO = 291,
DOTDOTDOT = 292,
NULL_TOK = 293,
UNDEF = 294,
CONST = 295,
INTERNAL = 296,
LINKONCE = 297,
WEAK = 298,
APPENDING = 299,
DLLIMPORT = 300,
DLLEXPORT = 301,
EXTERN_WEAK = 302,
OPAQUE = 303,
NOT = 304,
EXTERNAL = 305,
TARGET = 306,
TRIPLE = 307,
ENDIAN = 308,
POINTERSIZE = 309,
LITTLE = 310,
BIG = 311,
ALIGN = 312,
DEPLIBS = 313,
CALL = 314,
TAIL = 315,
ASM_TOK = 316,
MODULE = 317,
SIDEEFFECT = 318,
CC_TOK = 319,
CCC_TOK = 320,
CSRETCC_TOK = 321,
FASTCC_TOK = 322,
COLDCC_TOK = 323,
X86_STDCALLCC_TOK = 324,
X86_FASTCALLCC_TOK = 325,
RET = 326,
BR = 327,
SWITCH = 328,
INVOKE = 329,
UNWIND = 330,
UNREACHABLE = 331,
ADD = 332,
SUB = 333,
MUL = 334,
DIV = 335,
REM = 336,
AND = 337,
OR = 338,
XOR = 339,
SETLE = 340,
SETGE = 341,
SETLT = 342,
SETGT = 343,
SETEQ = 344,
SETNE = 345,
MALLOC = 346,
ALLOCA = 347,
FREE = 348,
LOAD = 349,
STORE = 350,
GETELEMENTPTR = 351,
PHI_TOK = 352,
CAST = 353,
SELECT = 354,
SHL = 355,
SHR = 356,
VAARG = 357,
EXTRACTELEMENT = 358,
INSERTELEMENT = 359,
SHUFFLEVECTOR = 360,
VAARG_old = 361,
VANEXT_old = 362
};
#endif
/* Tokens. */
#define ESINT64VAL 258
#define EUINT64VAL 259
#define SINTVAL 260
#define UINTVAL 261
#define FPVAL 262
#define VOID 263
#define BOOL 264
#define SBYTE 265
#define UBYTE 266
#define SHORT 267
#define USHORT 268
#define INT 269
#define UINT 270
#define LONG 271
#define ULONG 272
#define FLOAT 273
#define DOUBLE 274
#define TYPE 275
#define LABEL 276
#define VAR_ID 277
#define LABELSTR 278
#define STRINGCONSTANT 279
#define IMPLEMENTATION 280
#define ZEROINITIALIZER 281
#define TRUETOK 282
#define FALSETOK 283
#define BEGINTOK 284
#define ENDTOK 285
#define DECLARE 286
#define GLOBAL 287
#define CONSTANT 288
#define SECTION 289
#define VOLATILE 290
#define TO 291
#define DOTDOTDOT 292
#define NULL_TOK 293
#define UNDEF 294
#define CONST 295
#define INTERNAL 296
#define LINKONCE 297
#define WEAK 298
#define APPENDING 299
#define DLLIMPORT 300
#define DLLEXPORT 301
#define EXTERN_WEAK 302
#define OPAQUE 303
#define NOT 304
#define EXTERNAL 305
#define TARGET 306
#define TRIPLE 307
#define ENDIAN 308
#define POINTERSIZE 309
#define LITTLE 310
#define BIG 311
#define ALIGN 312
#define DEPLIBS 313
#define CALL 314
#define TAIL 315
#define ASM_TOK 316
#define MODULE 317
#define SIDEEFFECT 318
#define CC_TOK 319
#define CCC_TOK 320
#define CSRETCC_TOK 321
#define FASTCC_TOK 322
#define COLDCC_TOK 323
#define X86_STDCALLCC_TOK 324
#define X86_FASTCALLCC_TOK 325
#define RET 326
#define BR 327
#define SWITCH 328
#define INVOKE 329
#define UNWIND 330
#define UNREACHABLE 331
#define ADD 332
#define SUB 333
#define MUL 334
#define DIV 335
#define REM 336
#define AND 337
#define OR 338
#define XOR 339
#define SETLE 340
#define SETGE 341
#define SETLT 342
#define SETGT 343
#define SETEQ 344
#define SETNE 345
#define MALLOC 346
#define ALLOCA 347
#define FREE 348
#define LOAD 349
#define STORE 350
#define GETELEMENTPTR 351
#define PHI_TOK 352
#define CAST 353
#define SELECT 354
#define SHL 355
#define SHR 356
#define VAARG 357
#define EXTRACTELEMENT 358
#define INSERTELEMENT 359
#define SHUFFLEVECTOR 360
#define VAARG_old 361
#define VANEXT_old 362
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 966 "/proj/llvm/llvm/lib/AsmParser/llvmAsmParser.y"
typedef union YYSTYPE {
typedef union {
llvm::Module *ModuleVal;
llvm::Function *FunctionVal;
std::pair<llvm::PATypeHolder*, char*> *ArgVal;
@ -287,14 +37,111 @@ typedef union YYSTYPE {
llvm::Instruction::OtherOps OtherOpVal;
llvm::Module::Endianness Endianness;
} YYSTYPE;
/* Line 1447 of yacc.c. */
#line 292 "llvmAsmParser.tab.h"
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
#define ESINT64VAL 257
#define EUINT64VAL 258
#define SINTVAL 259
#define UINTVAL 260
#define FPVAL 261
#define VOID 262
#define BOOL 263
#define SBYTE 264
#define UBYTE 265
#define SHORT 266
#define USHORT 267
#define INT 268
#define UINT 269
#define LONG 270
#define ULONG 271
#define FLOAT 272
#define DOUBLE 273
#define TYPE 274
#define LABEL 275
#define VAR_ID 276
#define LABELSTR 277
#define STRINGCONSTANT 278
#define IMPLEMENTATION 279
#define ZEROINITIALIZER 280
#define TRUETOK 281
#define FALSETOK 282
#define BEGINTOK 283
#define ENDTOK 284
#define DECLARE 285
#define GLOBAL 286
#define CONSTANT 287
#define SECTION 288
#define VOLATILE 289
#define TO 290
#define DOTDOTDOT 291
#define NULL_TOK 292
#define UNDEF 293
#define CONST 294
#define INTERNAL 295
#define LINKONCE 296
#define WEAK 297
#define APPENDING 298
#define DLLIMPORT 299
#define DLLEXPORT 300
#define EXTERN_WEAK 301
#define OPAQUE 302
#define NOT 303
#define EXTERNAL 304
#define TARGET 305
#define TRIPLE 306
#define ENDIAN 307
#define POINTERSIZE 308
#define LITTLE 309
#define BIG 310
#define ALIGN 311
#define DEPLIBS 312
#define CALL 313
#define TAIL 314
#define ASM_TOK 315
#define MODULE 316
#define SIDEEFFECT 317
#define CC_TOK 318
#define CCC_TOK 319
#define CSRETCC_TOK 320
#define FASTCC_TOK 321
#define COLDCC_TOK 322
#define X86_STDCALLCC_TOK 323
#define X86_FASTCALLCC_TOK 324
#define RET 325
#define BR 326
#define SWITCH 327
#define INVOKE 328
#define UNWIND 329
#define UNREACHABLE 330
#define ADD 331
#define SUB 332
#define MUL 333
#define DIV 334
#define REM 335
#define AND 336
#define OR 337
#define XOR 338
#define SETLE 339
#define SETGE 340
#define SETLT 341
#define SETGT 342
#define SETEQ 343
#define SETNE 344
#define MALLOC 345
#define ALLOCA 346
#define FREE 347
#define LOAD 348
#define STORE 349
#define GETELEMENTPTR 350
#define PHI_TOK 351
#define CAST 352
#define SELECT 353
#define SHL 354
#define SHR 355
#define VAARG 356
#define EXTRACTELEMENT 357
#define INSERTELEMENT 358
#define SHUFFLEVECTOR 359
#define VAARG_old 360
#define VANEXT_old 361
extern YYSTYPE llvmAsmlval;

View File

@ -1562,11 +1562,11 @@ ConstVal : SIntType EINT64VAL { // integral constants
CHECK_FOR_ERROR
}
| BOOL TRUETOK { // Boolean constants
$$ = ConstantBool::True;
$$ = ConstantBool::getTrue();
CHECK_FOR_ERROR
}
| BOOL FALSETOK { // Boolean constants
$$ = ConstantBool::False;
$$ = ConstantBool::getFalse();
CHECK_FOR_ERROR
}
| FPType FPVAL { // Float & Double constants
@ -2076,11 +2076,11 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
CHECK_FOR_ERROR
}
| TRUETOK {
$$ = ValID::create(ConstantBool::True);
$$ = ValID::create(ConstantBool::getTrue());
CHECK_FOR_ERROR
}
| FALSETOK {
$$ = ValID::create(ConstantBool::False);
$$ = ValID::create(ConstantBool::getFalse());
CHECK_FOR_ERROR
}
| NULL_TOK {

View File

@ -1562,11 +1562,11 @@ ConstVal : SIntType EINT64VAL { // integral constants
CHECK_FOR_ERROR
}
| BOOL TRUETOK { // Boolean constants
$$ = ConstantBool::True;
$$ = ConstantBool::getTrue();
CHECK_FOR_ERROR
}
| BOOL FALSETOK { // Boolean constants
$$ = ConstantBool::False;
$$ = ConstantBool::getFalse();
CHECK_FOR_ERROR
}
| FPType FPVAL { // Float & Double constants
@ -2076,11 +2076,11 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
CHECK_FOR_ERROR
}
| TRUETOK {
$$ = ValID::create(ConstantBool::True);
$$ = ValID::create(ConstantBool::getTrue());
CHECK_FOR_ERROR
}
| FALSETOK {
$$ = ValID::create(ConstantBool::False);
$$ = ValID::create(ConstantBool::getFalse());
CHECK_FOR_ERROR
}
| NULL_TOK {

View File

@ -709,7 +709,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// keep track of whether the global was initialized yet or not.
GlobalVariable *InitBool =
new GlobalVariable(Type::BoolTy, false, GlobalValue::InternalLinkage,
ConstantBool::False, GV->getName()+".init");
ConstantBool::getFalse(), GV->getName()+".init");
bool InitBoolUsed = false;
// Loop over all uses of GV, processing them in turn.
@ -728,7 +728,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
switch (SCI->getOpcode()) {
default: assert(0 && "Unknown opcode!");
case Instruction::SetLT:
LV = ConstantBool::False; // X < null -> always false
LV = ConstantBool::getFalse(); // X < null -> always false
break;
case Instruction::SetEQ:
case Instruction::SetLE:
@ -747,7 +747,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
} else {
StoreInst *SI = cast<StoreInst>(GV->use_back());
// The global is initialized when the store to it occurs.
new StoreInst(ConstantBool::True, InitBool, SI);
new StoreInst(ConstantBool::getTrue(), InitBool, SI);
SI->eraseFromParent();
}
@ -859,7 +859,8 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
// Create the new global, initializing it to false.
GlobalVariable *NewGV = new GlobalVariable(Type::BoolTy, false,
GlobalValue::InternalLinkage, ConstantBool::False, GV->getName()+".b");
GlobalValue::InternalLinkage, ConstantBool::getFalse(),
GV->getName()+".b");
GV->getParent()->getGlobalList().insert(GV, NewGV);
Constant *InitVal = GV->getInitializer();

View File

@ -788,12 +788,12 @@ void CEE::PropagateBranchInfo(BranchInst *BI) {
// Propagate information into the true block...
//
PropagateEquality(BI->getCondition(), ConstantBool::True,
PropagateEquality(BI->getCondition(), ConstantBool::getTrue(),
getRegionInfo(BI->getSuccessor(0)));
// Propagate information into the false block...
//
PropagateEquality(BI->getCondition(), ConstantBool::False,
PropagateEquality(BI->getCondition(), ConstantBool::getFalse(),
getRegionInfo(BI->getSuccessor(1)));
}
@ -971,8 +971,7 @@ void CEE::IncorporateInstruction(Instruction *Inst, RegionInfo &RI) {
// See if we can figure out a result for this instruction...
Relation::KnownResult Result = getSetCCResult(SCI, RI);
if (Result != Relation::Unknown) {
PropagateEquality(SCI, Result ? ConstantBool::True : ConstantBool::False,
RI);
PropagateEquality(SCI, ConstantBool::get(Result != 0), RI);
}
}
}

View File

@ -1989,7 +1989,7 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::False);
UpdateValueUsesWith(CondI, ConstantBool::getFalse());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(2));
else
@ -2001,7 +2001,7 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::True);
UpdateValueUsesWith(CondI, ConstantBool::getTrue());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(1));
else
@ -2213,7 +2213,7 @@ Instruction *InstCombiner::visitRem(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::False);
UpdateValueUsesWith(CondI, ConstantBool::getFalse());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(2));
else
@ -2225,7 +2225,7 @@ Instruction *InstCombiner::visitRem(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::True);
UpdateValueUsesWith(CondI, ConstantBool::getTrue());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(1));
else
@ -2344,14 +2344,14 @@ static unsigned getSetCondCode(const SetCondInst *SCI) {
/// SetCC instruction.
static Value *getSetCCValue(unsigned Opcode, Value *LHS, Value *RHS) {
switch (Opcode) {
case 0: return ConstantBool::False;
case 0: return ConstantBool::getFalse();
case 1: return new SetCondInst(Instruction::SetGT, LHS, RHS);
case 2: return new SetCondInst(Instruction::SetEQ, LHS, RHS);
case 3: return new SetCondInst(Instruction::SetGE, LHS, RHS);
case 4: return new SetCondInst(Instruction::SetLT, LHS, RHS);
case 5: return new SetCondInst(Instruction::SetNE, LHS, RHS);
case 6: return new SetCondInst(Instruction::SetLE, LHS, RHS);
case 7: return ConstantBool::True;
case 7: return ConstantBool::getTrue();
default: assert(0 && "Illegal SetCCCode!"); return 0;
}
}
@ -2851,7 +2851,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
default: assert(0 && "Unknown integer condition code!");
case Instruction::SetEQ: // (X == 13 & X == 15) -> false
case Instruction::SetGT: // (X == 13 & X > 15) -> false
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
case Instruction::SetNE: // (X == 13 & X != 15) -> X == 13
case Instruction::SetLT: // (X == 13 & X < 15) -> X == 13
return ReplaceInstUsesWith(I, LHS);
@ -2886,7 +2886,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
default: assert(0 && "Unknown integer condition code!");
case Instruction::SetEQ: // (X < 13 & X == 15) -> false
case Instruction::SetGT: // (X < 13 & X > 15) -> false
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
case Instruction::SetNE: // (X < 13 & X != 15) -> X < 13
case Instruction::SetLT: // (X < 13 & X < 15) -> X < 13
return ReplaceInstUsesWith(I, LHS);
@ -3254,7 +3254,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return ReplaceInstUsesWith(I, LHS);
case Instruction::SetNE: // (X != 13 | X != 15) -> true
case Instruction::SetLT: // (X != 13 | X < 15) -> true
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
}
break;
case Instruction::SetLT:
@ -3277,7 +3277,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return ReplaceInstUsesWith(I, LHS);
case Instruction::SetNE: // (X > 13 | X != 15) -> true
case Instruction::SetLT: // (X > 13 | X < 15) -> true
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
}
}
}
@ -3339,7 +3339,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) {
// xor (setcc A, B), true = not (setcc A, B) = setncc A, B
if (SetCondInst *SCI = dyn_cast<SetCondInst>(Op0I))
if (RHS == ConstantBool::True && SCI->hasOneUse())
if (RHS == ConstantBool::getTrue() && SCI->hasOneUse())
return new SetCondInst(SCI->getInverseCondition(),
SCI->getOperand(0), SCI->getOperand(1));
@ -3781,9 +3781,9 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
// Check to see if we are comparing against the minimum or maximum value...
if (CI->isMinValue()) {
if (I.getOpcode() == Instruction::SetLT) // A < MIN -> FALSE
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
if (I.getOpcode() == Instruction::SetGE) // A >= MIN -> TRUE
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (I.getOpcode() == Instruction::SetLE) // A <= MIN -> A == MIN
return BinaryOperator::createSetEQ(Op0, Op1);
if (I.getOpcode() == Instruction::SetGT) // A > MIN -> A != MIN
@ -3791,9 +3791,9 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
} else if (CI->isMaxValue()) {
if (I.getOpcode() == Instruction::SetGT) // A > MAX -> FALSE
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
if (I.getOpcode() == Instruction::SetLE) // A <= MAX -> TRUE
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (I.getOpcode() == Instruction::SetGE) // A >= MAX -> A == MAX
return BinaryOperator::createSetEQ(Op0, Op1);
if (I.getOpcode() == Instruction::SetLT) // A < MAX -> A != MAX
@ -3842,19 +3842,23 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
default: assert(0 && "Unknown setcc opcode!");
case Instruction::SetEQ:
if (Max < RHSVal || Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetNE:
if (Max < RHSVal || Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
break;
case Instruction::SetLT:
if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
if (Max < RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetGT:
if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
if (Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (Max < RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
}
} else { // Signed comparison.
@ -3866,19 +3870,23 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
default: assert(0 && "Unknown setcc opcode!");
case Instruction::SetEQ:
if (Max < RHSVal || Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetNE:
if (Max < RHSVal || Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
break;
case Instruction::SetLT:
if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
if (Max < RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
case Instruction::SetGT:
if (Min > RHSVal) return ReplaceInstUsesWith(I, ConstantBool::True);
if (Max < RHSVal) return ReplaceInstUsesWith(I, ConstantBool::False);
if (Min > RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
if (Max < RHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
break;
}
}
@ -3978,9 +3986,9 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
// As a special case, check to see if this means that the
// result is always true or false now.
if (I.getOpcode() == Instruction::SetEQ)
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
if (I.getOpcode() == Instruction::SetNE)
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
} else {
I.setOperand(1, NewCst);
Constant *NewAndCST;
@ -4200,7 +4208,7 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
default: assert(0 && "Unhandled setcc opcode!");
case Instruction::SetEQ:
if (LoOverflow && HiOverflow)
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
else if (HiOverflow)
return new SetCondInst(Instruction::SetGE, X, LoBound);
else if (LoOverflow)
@ -4209,7 +4217,7 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
return InsertRangeTest(X, LoBound, HiBound, true, I);
case Instruction::SetNE:
if (LoOverflow && HiOverflow)
return ReplaceInstUsesWith(I, ConstantBool::True);
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
else if (HiOverflow)
return new SetCondInst(Instruction::SetLT, X, LoBound);
else if (LoOverflow)
@ -4218,11 +4226,11 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
return InsertRangeTest(X, LoBound, HiBound, false, I);
case Instruction::SetLT:
if (LoOverflow)
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return new SetCondInst(Instruction::SetLT, X, LoBound);
case Instruction::SetGT:
if (HiOverflow)
return ReplaceInstUsesWith(I, ConstantBool::False);
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return new SetCondInst(Instruction::SetGE, X, HiBound);
}
}
@ -4558,9 +4566,9 @@ Instruction *InstCombiner::visitSetCondInstWithCastAndCast(SetCondInst &SCI) {
// If the value cannot be represented in the shorter type, we cannot emit
// a simple comparison.
if (SCI.getOpcode() == Instruction::SetEQ)
return ReplaceInstUsesWith(SCI, ConstantBool::False);
return ReplaceInstUsesWith(SCI, ConstantBool::getFalse());
if (SCI.getOpcode() == Instruction::SetNE)
return ReplaceInstUsesWith(SCI, ConstantBool::True);
return ReplaceInstUsesWith(SCI, ConstantBool::getTrue());
// Evaluate the comparison for LT.
Value *Result;
@ -4569,21 +4577,21 @@ Instruction *InstCombiner::visitSetCondInstWithCastAndCast(SetCondInst &SCI) {
if (isSignSrc) {
// Signed extend and signed comparison.
if (cast<ConstantSInt>(CI)->getValue() < 0) // X < (small) --> false
Result = ConstantBool::False;
Result = ConstantBool::getFalse();
else
Result = ConstantBool::True; // X < (large) --> true
Result = ConstantBool::getTrue(); // X < (large) --> true
} else {
// Unsigned extend and signed comparison.
if (cast<ConstantSInt>(CI)->getValue() < 0)
Result = ConstantBool::False;
Result = ConstantBool::getFalse();
else
Result = ConstantBool::True;
Result = ConstantBool::getTrue();
}
} else {
// We're performing an unsigned comparison.
if (!isSignSrc) {
// Unsigned extend & compare -> always true.
Result = ConstantBool::True;
Result = ConstantBool::getTrue();
} else {
// We're performing an unsigned comp with a sign extended value.
// This is true if the input is >= 0. [aka >s -1]
@ -5389,7 +5397,7 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
// cast (xor bool X, true) to int --> xor (cast bool X to int), 1
if (SrcBitSize == 1 && SrcI->getOpcode() == Instruction::Xor &&
Op1 == ConstantBool::True &&
Op1 == ConstantBool::getTrue() &&
(!Op0->hasOneUse() || !isa<SetCondInst>(Op0))) {
Value *New = InsertOperandCastBefore(Op0, DestTy, &CI);
return BinaryOperator::createXor(New,
@ -5648,12 +5656,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
// select true, X, Y -> X
// select false, X, Y -> Y
if (ConstantBool *C = dyn_cast<ConstantBool>(CondVal))
if (C == ConstantBool::True)
return ReplaceInstUsesWith(SI, TrueVal);
else {
assert(C == ConstantBool::False);
return ReplaceInstUsesWith(SI, FalseVal);
}
return ReplaceInstUsesWith(SI, C->getValue() ? TrueVal : FalseVal);
// select C, X, X -> X
if (TrueVal == FalseVal)
@ -5672,7 +5675,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
if (SI.getType() == Type::BoolTy)
if (ConstantBool *C = dyn_cast<ConstantBool>(TrueVal)) {
if (C == ConstantBool::True) {
if (C->getValue()) {
// Change: A = select B, true, C --> A = or B, C
return BinaryOperator::createOr(CondVal, FalseVal);
} else {
@ -5683,7 +5686,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
return BinaryOperator::createAnd(NotCond, FalseVal);
}
} else if (ConstantBool *C = dyn_cast<ConstantBool>(FalseVal)) {
if (C == ConstantBool::False) {
if (C->getValue() == false) {
// Change: A = select B, C, false --> A = and B, C
return BinaryOperator::createAnd(CondVal, TrueVal);
} else {
@ -6193,7 +6196,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
Instruction *OldCall = CS.getInstruction();
// If the call and callee calling conventions don't match, this call must
// be unreachable, as the call is undefined.
new StoreInst(ConstantBool::True,
new StoreInst(ConstantBool::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)), OldCall);
if (!OldCall->use_empty())
OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType()));
@ -6206,7 +6209,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
// This instruction is not reachable, just remove it. We insert a store to
// undef so that we know that this code is not reachable, despite the fact
// that we can't modify the CFG here.
new StoreInst(ConstantBool::True,
new StoreInst(ConstantBool::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)),
CS.getInstruction());
@ -6217,7 +6220,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
if (InvokeInst *II = dyn_cast<InvokeInst>(CS.getInstruction())) {
// Don't break the CFG, insert a dummy cond branch.
new BranchInst(II->getNormalDest(), II->getUnwindDest(),
ConstantBool::True, II);
ConstantBool::getTrue(), II);
}
return EraseInstFromFunction(*CS.getInstruction());
}
@ -6901,7 +6904,7 @@ Instruction *InstCombiner::visitFreeInst(FreeInst &FI) {
// free undef -> unreachable.
if (isa<UndefValue>(Op)) {
// Insert a new store to null because we cannot modify the CFG here.
new StoreInst(ConstantBool::True,
new StoreInst(ConstantBool::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)), &FI);
return EraseInstFromFunction(FI);
}

View File

@ -173,7 +173,8 @@ bool LoopUnswitch::visitLoop(Loop *L) {
// See if this, or some part of it, is loop invariant. If so, we can
// unswitch on it if we desire.
Value *LoopCond = FindLIVLoopCondition(BI->getCondition(), L, Changed);
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::True, L)) {
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::getTrue(),
L)) {
++NumBranches;
return true;
}
@ -196,7 +197,8 @@ bool LoopUnswitch::visitLoop(Loop *L) {
BBI != E; ++BBI)
if (SelectInst *SI = dyn_cast<SelectInst>(BBI)) {
Value *LoopCond = FindLIVLoopCondition(SI->getCondition(), L, Changed);
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::True, L)) {
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::getTrue(),
L)) {
++NumSelects;
return true;
}
@ -286,9 +288,9 @@ static bool IsTrivialUnswitchCondition(Loop *L, Value *Cond, Constant **Val = 0,
// side-effects. If so, determine the value of Cond that causes it to do
// this.
if ((LoopExitBB = isTrivialLoopExitBlock(L, BI->getSuccessor(0)))) {
if (Val) *Val = ConstantBool::True;
if (Val) *Val = ConstantBool::getTrue();
} else if ((LoopExitBB = isTrivialLoopExitBlock(L, BI->getSuccessor(1)))) {
if (Val) *Val = ConstantBool::False;
if (Val) *Val = ConstantBool::getFalse();
}
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(HeaderTerm)) {
// If this isn't a switch on Cond, we can't handle it.
@ -488,7 +490,7 @@ static void EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val,
Value *BranchVal = LIC;
if (!isa<ConstantBool>(Val)) {
BranchVal = BinaryOperator::createSetEQ(LIC, Val, "tmp", InsertPt);
} else if (Val != ConstantBool::True) {
} else if (Val != ConstantBool::getTrue()) {
// We want to enter the new loop when the condition is true.
std::swap(TrueDest, FalseDest);
}
@ -964,10 +966,9 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
BasicBlock* Split = SplitBlock(Old, SI);
Instruction* OldTerm = Old->getTerminator();
BranchInst* Branch = new BranchInst(Split,
SI->getSuccessor(i),
ConstantBool::True,
OldTerm);
BranchInst* Branch = new BranchInst(Split, SI->getSuccessor(i),
ConstantBool::getTrue(),
OldTerm);
Old->getTerminator()->eraseFromParent();

View File

@ -315,51 +315,47 @@ namespace {
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V2)) {
switch (BO->getOpcode()) {
case Instruction::SetEQ:
if (V1 == ConstantBool::True)
add(Opcode, BO->getOperand(0), BO->getOperand(1), false);
if (V1 == ConstantBool::False)
add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
if (ConstantBool *V1CB = dyn_cast<ConstantBool>(V1))
add(Opcode, BO->getOperand(0), BO->getOperand(1),!V1CB->getValue());
break;
case Instruction::SetNE:
if (V1 == ConstantBool::True)
add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
if (V1 == ConstantBool::False)
add(Opcode, BO->getOperand(0), BO->getOperand(1), false);
if (ConstantBool *V1CB = dyn_cast<ConstantBool>(V1))
add(Opcode, BO->getOperand(0), BO->getOperand(1), V1CB->getValue());
break;
case Instruction::SetLT:
case Instruction::SetGT:
if (V1 == ConstantBool::True)
if (V1 == ConstantBool::getTrue())
add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
break;
case Instruction::SetLE:
case Instruction::SetGE:
if (V1 == ConstantBool::False)
if (V1 == ConstantBool::getFalse())
add(Opcode, BO->getOperand(0), BO->getOperand(1), true);
break;
case Instruction::And:
if (V1 == ConstantBool::True) {
add(Opcode, ConstantBool::True, BO->getOperand(0), false);
add(Opcode, ConstantBool::True, BO->getOperand(1), false);
if (V1 == ConstantBool::getTrue()) {
add(Opcode, V1, BO->getOperand(0), false);
add(Opcode, V1, BO->getOperand(1), false);
}
break;
case Instruction::Or:
if (V1 == ConstantBool::False) {
add(Opcode, ConstantBool::False, BO->getOperand(0), false);
add(Opcode, ConstantBool::False, BO->getOperand(1), false);
if (V1 == ConstantBool::getFalse()) {
add(Opcode, V1, BO->getOperand(0), false);
add(Opcode, V1, BO->getOperand(1), false);
}
break;
case Instruction::Xor:
if (V1 == ConstantBool::True) {
if (BO->getOperand(0) == ConstantBool::True)
add(Opcode, ConstantBool::False, BO->getOperand(1), false);
if (BO->getOperand(1) == ConstantBool::True)
add(Opcode, ConstantBool::False, BO->getOperand(0), false);
if (V1 == ConstantBool::getTrue()) {
if (BO->getOperand(0) == V1)
add(Opcode, ConstantBool::getFalse(), BO->getOperand(1), false);
if (BO->getOperand(1) == V1)
add(Opcode, ConstantBool::getFalse(), BO->getOperand(0), false);
}
if (V1 == ConstantBool::False) {
if (BO->getOperand(0) == ConstantBool::True)
add(Opcode, ConstantBool::True, BO->getOperand(1), false);
if (BO->getOperand(1) == ConstantBool::True)
add(Opcode, ConstantBool::True, BO->getOperand(0), false);
if (V1 == ConstantBool::getFalse()) {
if (BO->getOperand(0) == ConstantBool::getTrue())
add(Opcode, ConstantBool::getTrue(), BO->getOperand(1), false);
if (BO->getOperand(1) == ConstantBool::getTrue())
add(Opcode, ConstantBool::getTrue(), BO->getOperand(0), false);
}
break;
default:
@ -368,10 +364,8 @@ namespace {
} else if (SelectInst *SI = dyn_cast<SelectInst>(V2)) {
if (Opcode != EQ && Opcode != NE) return;
ConstantBool *True = (Opcode==EQ) ? ConstantBool::True
: ConstantBool::False,
*False = (Opcode==EQ) ? ConstantBool::False
: ConstantBool::True;
ConstantBool *True = ConstantBool::get(Opcode==EQ),
*False = ConstantBool::get(Opcode!=EQ);
if (V1 == SI->getTrueValue())
addEqual(SI->getCondition(), True);
@ -525,8 +519,8 @@ Value *PredicateSimplifier::resolve(SetCondInst *SCI,
if (NE != KP.Properties.end()) {
switch (SCI->getOpcode()) {
case Instruction::SetEQ: return ConstantBool::False;
case Instruction::SetNE: return ConstantBool::True;
case Instruction::SetEQ: return ConstantBool::getFalse();
case Instruction::SetNE: return ConstantBool::getTrue();
case Instruction::SetLE:
case Instruction::SetGE:
case Instruction::SetLT:
@ -558,10 +552,9 @@ Value *PredicateSimplifier::resolve(BinaryOperator *BO,
Value *PredicateSimplifier::resolve(SelectInst *SI, const PropertySet &KP) {
Value *Condition = resolve(SI->getCondition(), KP);
if (Condition == ConstantBool::True)
return resolve(SI->getTrueValue(), KP);
else if (Condition == ConstantBool::False)
return resolve(SI->getFalseValue(), KP);
if (ConstantBool *CB = dyn_cast<ConstantBool>(Condition))
return resolve(CB->getValue() ? SI->getTrueValue() : SI->getFalseValue(),
KP);
return SI;
}
@ -674,10 +667,10 @@ void PredicateSimplifier::visit(BranchInst *BI, PropertySet &KP) {
BasicBlock *TrueDest = BI->getSuccessor(0),
*FalseDest = BI->getSuccessor(1);
if (Condition == ConstantBool::True || TrueDest == FalseDest) {
if (Condition == ConstantBool::getTrue() || TrueDest == FalseDest) {
proceedToSuccessors(KP, BB);
return;
} else if (Condition == ConstantBool::False) {
} else if (Condition == ConstantBool::getFalse()) {
proceedToSuccessors(KP, BB);
return;
}
@ -686,14 +679,14 @@ void PredicateSimplifier::visit(BranchInst *BI, PropertySet &KP) {
for (DTNodeType::iterator I = Node->begin(), E = Node->end(); I != E; ++I) {
if ((*I)->getBlock() == TrueDest) {
PropertySet TrueProperties(KP);
TrueProperties.addEqual(ConstantBool::True, Condition);
TrueProperties.addEqual(ConstantBool::getTrue(), Condition);
proceedToSuccessor(BI, 0, KP, TrueProperties);
continue;
}
if ((*I)->getBlock() == FalseDest) {
PropertySet FalseProperties(KP);
FalseProperties.addEqual(ConstantBool::False, Condition);
FalseProperties.addEqual(ConstantBool::getFalse(), Condition);
proceedToSuccessor(BI, 1, KP, FalseProperties);
continue;
}

View File

@ -374,7 +374,7 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
Succs[0] = Succs[1] = true;
} else if (BCValue.isConstant()) {
// Constant condition variables mean the branch can only go a single way
Succs[BCValue.getConstant() == ConstantBool::False] = true;
Succs[BCValue.getConstant() == ConstantBool::getFalse()] = true;
}
}
} else if (InvokeInst *II = dyn_cast<InvokeInst>(&TI)) {
@ -432,7 +432,7 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
// Constant condition variables mean the branch can only go a single way
return BI->getSuccessor(BCValue.getConstant() ==
ConstantBool::False) == To;
ConstantBool::getFalse()) == To;
}
return false;
}
@ -598,12 +598,9 @@ void SCCPSolver::visitSelectInst(SelectInst &I) {
if (CondValue.isUndefined())
return;
if (CondValue.isConstant()) {
Value *InVal = 0;
if (CondValue.getConstant() == ConstantBool::True) {
mergeInValue(&I, getValueState(I.getTrueValue()));
return;
} else if (CondValue.getConstant() == ConstantBool::False) {
mergeInValue(&I, getValueState(I.getFalseValue()));
if (ConstantBool *CondCB = dyn_cast<ConstantBool>(CondValue.getConstant())){
mergeInValue(&I, getValueState(CondCB->getValue() ? I.getTrueValue()
: I.getFalseValue()));
return;
}
}
@ -1035,7 +1032,7 @@ bool SCCPSolver::ResolveBranchesIn(Function &F) {
if (BI->isConditional()) {
LatticeVal &BCValue = getValueState(BI->getCondition());
if (BCValue.isUndefined()) {
BI->setCondition(ConstantBool::True);
BI->setCondition(ConstantBool::getTrue());
BranchesResolved = true;
visit(BI);
}