diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2015-02-13 16:33:34 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2015-02-13 16:33:34 +0000 |
commit | 30d471f6aa34731861e892ee2652380d2c4617c3 (patch) | |
tree | c05a6533a355d13725917eeae7ae06b6e27a9eed /llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | |
parent | 7ce96b853dffeca7e37c78fa4a02fe8415b3ab9b (diff) | |
download | llvm-30d471f6aa34731861e892ee2652380d2c4617c3.zip llvm-30d471f6aa34731861e892ee2652380d2c4617c3.tar.gz llvm-30d471f6aa34731861e892ee2652380d2c4617c3.tar.bz2 |
[InstCombine] Fix regression introduced at r227197.
This patch fixes a problem I accidentally introduced in an instruction combine
on select instructions added at r227197. That revision taught the instruction
combiner how to fold a cttz/ctlz followed by a icmp plus select into a single
cttz/ctlz with flag 'is_zero_undef' cleared.
However, the new rule added at r227197 would have produced wrong results in the
case where a cttz/ctlz with flag 'is_zero_undef' cleared was follwed by a
zero-extend or truncate. In that case, the folded instruction would have
been inserted in a wrong location thus leaving the CFG in an inconsistent
state.
This patch fixes the problem and add two reproducible test cases to
existing test 'InstCombine/select-cmp-cttz-ctlz.ll'.
llvm-svn: 229124
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 0debe63..b92d90d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -482,16 +482,12 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal, match(Count, m_Intrinsic<Intrinsic::ctlz>(m_Specific(CmpLHS)))) { IntrinsicInst *II = cast<IntrinsicInst>(Count); IRBuilder<> Builder(II); - if (cast<ConstantInt>(II->getArgOperand(1))->isOne()) { - // Explicitly clear the 'undef_on_zero' flag. - IntrinsicInst *NewI = cast<IntrinsicInst>(II->clone()); - Type *Ty = NewI->getArgOperand(1)->getType(); - NewI->setArgOperand(1, Constant::getNullValue(Ty)); - Builder.Insert(NewI); - Count = NewI; - } - - return Builder.CreateZExtOrTrunc(Count, ValueOnZero->getType()); + // Explicitly clear the 'undef_on_zero' flag. + IntrinsicInst *NewI = cast<IntrinsicInst>(II->clone()); + Type *Ty = NewI->getArgOperand(1)->getType(); + NewI->setArgOperand(1, Constant::getNullValue(Ty)); + Builder.Insert(NewI); + return Builder.CreateZExtOrTrunc(NewI, ValueOnZero->getType()); } return nullptr; |