diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-02-17 14:50:13 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-02-17 14:50:13 +0000 |
| commit | ac3952052bdc0ed601e54ed1454674755d2b2a6e (patch) | |
| tree | b9cbfd28ee81780b9eefa9ce3d4369fb8a2bb78d /llvm/lib | |
| parent | a63a5b993ee90e7da6afc052c6702709f39dd9eb (diff) | |
| download | bcm5719-llvm-ac3952052bdc0ed601e54ed1454674755d2b2a6e.tar.gz bcm5719-llvm-ac3952052bdc0ed601e54ed1454674755d2b2a6e.zip | |
[InstSimplify] move select undef cond fold with other constant cond folds; NFCI
llvm-svn: 325434
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index e81d7672b88..34a10c5d5ea 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3681,37 +3681,38 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, /// Given operands for a SelectInst, see if we can fold the result. /// If not, this returns null. -static Value *SimplifySelectInst(Value *CondVal, Value *TrueVal, - Value *FalseVal, const SimplifyQuery &Q, - unsigned MaxRecurse) { - // select true, X, Y -> X - // select false, X, Y -> Y - if (Constant *CB = dyn_cast<Constant>(CondVal)) { - if (Constant *CT = dyn_cast<Constant>(TrueVal)) - if (Constant *CF = dyn_cast<Constant>(FalseVal)) - return ConstantFoldSelectInstruction(CB, CT, CF); - if (CB->isAllOnesValue()) +static Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, + const SimplifyQuery &Q, unsigned MaxRecurse) { + if (auto *CondC = dyn_cast<Constant>(Cond)) { + if (auto *TrueC = dyn_cast<Constant>(TrueVal)) + if (auto *FalseC = dyn_cast<Constant>(FalseVal)) + return ConstantFoldSelectInstruction(CondC, TrueC, FalseC); + + // select undef, X, Y -> X or Y + if (isa<UndefValue>(CondC)) + return isa<Constant>(FalseVal) ? FalseVal : TrueVal; + + // TODO: Vector constants with undef elements don't simplify. + + // select true, X, Y -> X + if (CondC->isAllOnesValue()) return TrueVal; - if (CB->isNullValue()) + // select false, X, Y -> Y + if (CondC->isNullValue()) return FalseVal; } - // select C, X, X -> X + // select ?, X, X -> X if (TrueVal == FalseVal) return TrueVal; - if (isa<UndefValue>(CondVal)) { // select undef, X, Y -> X or Y - if (isa<Constant>(FalseVal)) - return FalseVal; - return TrueVal; - } - if (isa<UndefValue>(TrueVal)) // select C, undef, X -> X + if (isa<UndefValue>(TrueVal)) // select ?, undef, X -> X return FalseVal; - if (isa<UndefValue>(FalseVal)) // select C, X, undef -> X + if (isa<UndefValue>(FalseVal)) // select ?, X, undef -> X return TrueVal; if (Value *V = - simplifySelectWithICmpCond(CondVal, TrueVal, FalseVal, Q, MaxRecurse)) + simplifySelectWithICmpCond(Cond, TrueVal, FalseVal, Q, MaxRecurse)) return V; return nullptr; |

