aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-11-21 15:44:56 +0100
committerNikita Popov <npopov@redhat.com>2023-11-21 15:47:55 +0100
commitac75171d41f0000d53eadf64a943d6fabc24af6c (patch)
tree1b5dba261487c17bef295bca691b664902588baa /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
parenta1652fdb5ebf4a7d94d28200765232ebc2ba7c62 (diff)
downloadllvm-ac75171d41f0000d53eadf64a943d6fabc24af6c.zip
llvm-ac75171d41f0000d53eadf64a943d6fabc24af6c.tar.gz
llvm-ac75171d41f0000d53eadf64a943d6fabc24af6c.tar.bz2
[InstCombine] Fix incorrect nneg inference on shift amount
Whether this is valid depends on the bit widths of the involved integers. Fixes https://github.com/llvm/llvm-project/issues/72927.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 1b2615d4..d2c6ffe 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1223,7 +1223,9 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
if (!Zext.hasNonNeg()) {
// If this zero extend is only used by a shift, add nneg flag.
- if (Zext.hasOneUse() && SrcTy->getScalarSizeInBits() > 2 &&
+ if (Zext.hasOneUse() &&
+ SrcTy->getScalarSizeInBits() >
+ Log2_64_Ceil(DestTy->getScalarSizeInBits()) &&
match(Zext.user_back(), m_Shift(m_Value(), m_Specific(&Zext)))) {
Zext.setNonNeg();
return &Zext;