Skip to content

Commit 9c02704

Browse files
Update shift-knownbits.ll
1 parent 6e4ff4f commit 9c02704

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

llvm/test/Transforms/InstSimplify/shift-knownbits.ll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -505,26 +505,25 @@ define <1 x i64> @bitcast_noshift_vector_wrong_type(<2 x float> %v1, <1 x i64> %
505505
; (e.g., 4 elements) was checked instead of the full demanded vector width (8 elements),
506506
; leading to incorrect known bits and removal of the `ashr` instruction.
507507

508+
; Test that verifies correct handling of known bits when bitcasting from a smaller vector
509+
; to a larger one (e.g., <2 x i32> to <8 x i8>). Previously, only the subscale portion
510+
; (e.g., 4 elements) was checked instead of the full demanded vector width (8 elements),
511+
; leading to incorrect known bits and removal of the `ashr` instruction.
512+
508513
define <8 x i8> @bitcast_knownbits_subscale_miscompile(i32 %x) {
509514
; CHECK-LABEL: @bitcast_knownbits_subscale_miscompile(
510515
; CHECK-NEXT: [[MASKED:%.*]] = and i32 [[X:%.*]], -256
511-
; CHECK-NEXT: [[BITCAST:%.*]] = bitcast i32 [[MASKED]] to <4 x i8>
512-
; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <4 x i8> [[BITCAST]], i32 3
513-
; CHECK-NEXT: [[COND:%.*]] = icmp eq i8 [[EXTRACT]], -113
514-
; CHECK-NEXT: call void @llvm.assume(i1 [[COND]])
515-
; CHECK-NEXT: [[INSERT:%.*]] = insertelement <2 x i32> poison, i32 [[MASKED]], i32 0
516+
; CHECK-NEXT: [[SETBITS:%.*]] = or i32 [[MASKED]], -16777216
517+
; CHECK-NEXT: [[INSERT:%.*]] = insertelement <2 x i32> poison, i32 [[SETBITS]], i32 0
516518
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <2 x i32> [[INSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
517519
; CHECK-NEXT: [[VEC:%.*]] = bitcast <2 x i32> [[SPLAT]] to <8 x i8>
518520
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <8 x i8> [[VEC]], <8 x i8> zeroinitializer, <8 x i32> <i32 7, i32 7, i32 7, i32 7, i32 0, i32 0, i32 0, i32 0>
519521
; CHECK-NEXT: [[SHR:%.*]] = ashr <8 x i8> [[SHUF]], splat (i8 1)
520522
; CHECK-NEXT: ret <8 x i8> [[SHR]]
521523
;
522524
%masked = and i32 %x, u0xFFFFFF00
523-
%bitcast = bitcast i32 %masked to <4 x i8>
524-
%extract = extractelement <4 x i8> %bitcast, i32 3
525-
%cond = icmp eq i8 %extract, u0x8F
526-
call void @llvm.assume(i1 %cond)
527-
%insert = insertelement <2 x i32> poison, i32 %masked, i32 0
525+
%setbits = or i32 %masked, u0xFF000000
526+
%insert = insertelement <2 x i32> poison, i32 %setbits, i32 0
528527
%splat = shufflevector <2 x i32> %insert, <2 x i32> poison, <2 x i32> splat (i32 0)
529528
%vec = bitcast <2 x i32> %splat to <8 x i8>
530529
%shuf = shufflevector <8 x i8> %vec, <8 x i8> zeroinitializer, <8 x i32> <i32 7, i32 7, i32 7, i32 7, i32 0, i32 0, i32 0, i32 0>

0 commit comments

Comments
 (0)