From d669758d84217f7e057740053783e012369337d0 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sun, 9 Jun 2019 16:30:42 +0000 Subject: [InstCombine] foldICmpWithLowBitMaskedVal(): 'icmp sgt/sle': avoid miscompiles A precondition 'x != 0' was forgotten by me: https://rise4fun.com/Alive/JFNP https://rise4fun.com/Alive/jHvL These 4 folds with non-constants could be re-enabled, but for now let's go for the simplest solution. https://bugs.llvm.org/show_bug.cgi?id=42198 llvm-svn: 362911 --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index a04e56916f8..0cfd930003a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3110,6 +3110,10 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I, // x s> x & (-1 >> y) -> x s> (-1 >> y) if (X != I.getOperand(0)) // X must be on LHS of comparison! return nullptr; // Ignore the other case. + if (!match(M, m_Constant())) // Can not do this fold with non-constant. + return nullptr; + if (!match(M, m_NonNegative())) // Must not have any -1 vector elements. + return nullptr; DstPred = ICmpInst::Predicate::ICMP_SGT; break; case ICmpInst::Predicate::ICMP_SGE: @@ -3136,6 +3140,10 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I, // x s<= x & (-1 >> y) -> x s<= (-1 >> y) if (X != I.getOperand(0)) // X must be on LHS of comparison! return nullptr; // Ignore the other case. + if (!match(M, m_Constant())) // Can not do this fold with non-constant. + return nullptr; + if (!match(M, m_NonNegative())) // Must not have any -1 vector elements. + return nullptr; DstPred = ICmpInst::Predicate::ICMP_SLE; break; default: -- cgit v1.2.3