Skip to content

Commit ac75171

Browse files
committed
[InstCombine] Fix incorrect nneg inference on shift amount
Whether this is valid depends on the bit widths of the involved integers. Fixes llvm/llvm-project#72927.
1 parent a1652fd commit ac75171

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,9 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
12231223

12241224
if (!Zext.hasNonNeg()) {
12251225
// If this zero extend is only used by a shift, add nneg flag.
1226-
if (Zext.hasOneUse() && SrcTy->getScalarSizeInBits() > 2 &&
1226+
if (Zext.hasOneUse() &&
1227+
SrcTy->getScalarSizeInBits() >
1228+
Log2_64_Ceil(DestTy->getScalarSizeInBits()) &&
12271229
match(Zext.user_back(), m_Shift(m_Value(), m_Specific(&Zext)))) {
12281230
Zext.setNonNeg();
12291231
return &Zext;

llvm/test/Transforms/InstCombine/shift.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,8 +2208,8 @@ define i128 @shift_zext_nneg(i8 %arg) {
22082208

22092209
define i129 @shift_zext_not_nneg(i8 %arg) {
22102210
; CHECK-LABEL: @shift_zext_not_nneg(
2211-
; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[ARG:%.*]] to i129
2212-
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i129 1, [[EXT]]
2211+
; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[ARG:%.*]] to i129
2212+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i129 1, [[EXT]]
22132213
; CHECK-NEXT: ret i129 [[SHL]]
22142214
;
22152215
%ext = zext i8 %arg to i129

0 commit comments

Comments
 (0)