Skip to content

Commit 0df3200

Browse files
committed
[ValueTracking] Fix KnownBits conflict for poison-only vector
If all the demanded elements are poison, return unknown instead of conflict to avoid downstream assertions. Fixes llvm#75505.
1 parent 469374e commit 0df3200

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,8 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
18261826
Known.Zero &= ~Elt;
18271827
Known.One &= Elt;
18281828
}
1829+
if (Known.hasConflict())
1830+
Known.resetAll();
18291831
return;
18301832
}
18311833

@@ -1849,6 +1851,8 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
18491851
Known.Zero &= ~Elt;
18501852
Known.One &= Elt;
18511853
}
1854+
if (Known.hasConflict())
1855+
Known.resetAll();
18521856
return;
18531857
}
18541858

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
3+
4+
; Just make sure that we don't assert.
5+
define i32 @test(<2 x i16> %a, i32 %b) {
6+
; CHECK-LABEL: define i32 @test(
7+
; CHECK-SAME: <2 x i16> [[A:%.*]], i32 [[B:%.*]]) {
8+
; CHECK-NEXT: [[MUL:%.*]] = mul <2 x i16> [[A]], <i16 -1, i16 poison>
9+
; CHECK-NEXT: [[BC:%.*]] = bitcast <2 x i16> [[MUL]] to i32
10+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[B]], [[BC]]
11+
; CHECK-NEXT: ret i32 [[LSHR]]
12+
;
13+
%mul = mul <2 x i16> %a, <i16 -1, i16 poison>
14+
%bc = bitcast <2 x i16> %mul to i32
15+
%lshr = lshr i32 %b, %bc
16+
ret i32 %lshr
17+
}

0 commit comments

Comments
 (0)