Skip to content

Commit 4a46021

Browse files
committed
offload demandedElts to wrapper function
1 parent be31853 commit 4a46021

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3926,27 +3926,24 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
39263926
Value *Src = U->getOperand(0);
39273927
Type *SrcTy = Src->getType();
39283928

3929+
// Skip if the source type is not an integer or integer vector type
3930+
// This ensures we only process integer-like types
39293931
if (!SrcTy->isIntOrIntVectorTy())
39303932
break;
39313933

39323934
unsigned SrcBits = SrcTy->getScalarSizeInBits();
39333935

3936+
// Bitcast 'large element' scalar/vector to 'small element' vector.
39343937
if ((SrcBits % TyBits) != 0)
39353938
break;
39363939

3940+
// Only proceed if the destination type is a fixed-size vector
39373941
if (isa<FixedVectorType>(Ty)) {
3938-
if (auto *SrcVTy = dyn_cast<FixedVectorType>(SrcTy)) {
3939-
APInt SrcDemandedElts =
3940-
APInt::getSplat(SrcVTy->getNumElements(), APInt(1, 1));
3941-
3942-
Tmp = ComputeNumSignBits(Src, SrcDemandedElts, Depth + 1, Q);
3943-
if (Tmp == SrcBits)
3944-
return TyBits;
3945-
} else {
3946-
Tmp = ComputeNumSignBits(Src, APInt(1, 1), Depth + 1, Q);
3947-
if (Tmp == SrcBits)
3948-
return TyBits;
3949-
}
3942+
// Fast case - sign splat can be simply split across the small elements.
3943+
// This works for both vector and scalar sources
3944+
Tmp = ComputeNumSignBits(Src, Depth + 1, Q);
3945+
if (Tmp == SrcBits)
3946+
return TyBits;
39503947
}
39513948
break;
39523949
}

llvm/test/Transforms/InstCombine/compute-sign-bits-bitcast.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define <8 x i8> @test_multiple_shifts(i1 %cond) {
4747
ret <8 x i8> %sra2
4848
}
4949

50-
; Case 4: Test with non-sign-extended source
50+
; (Negative) Case 4: Test with non-sign-extended source
5151
define <4 x i8> @test_non_sign_extended(i32 %val) {
5252
; CHECK-LABEL: define <4 x i8> @test_non_sign_extended(
5353
; CHECK-SAME: i32 [[VAL:%.*]]) {

0 commit comments

Comments
 (0)