Skip to content

Commit 97e3220

Browse files
committed
[InstSimplify] Consider bitcast as potential cross-lane operation
The bitcast might change the number of vector lanes, in which case it will be a cross-lane operation. Fixes #77320.
1 parent ade7ae4 commit 97e3220

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4313,7 +4313,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
43134313
// For vector types, the simplification must hold per-lane, so forbid
43144314
// potentially cross-lane operations like shufflevector.
43154315
if (!I->getType()->isVectorTy() || isa<ShuffleVectorInst>(I) ||
4316-
isa<CallBase>(I))
4316+
isa<CallBase>(I) || isa<BitCastInst>(I))
43174317
return nullptr;
43184318
}
43194319

llvm/test/Transforms/InstSimplify/select.ll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,10 +1734,15 @@ define i8 @select_or_disjoint_eq(i8 %x, i8 %y) {
17341734
ret i8 %sel
17351735
}
17361736

1737-
; FIXME: This is a miscompile.
17381737
define <4 x i32> @select_vector_cmp_with_bitcasts(<2 x i64> %x, <4 x i32> %y) {
17391738
; CHECK-LABEL: @select_vector_cmp_with_bitcasts(
1740-
; CHECK-NEXT: ret <4 x i32> zeroinitializer
1739+
; CHECK-NEXT: [[X_BC:%.*]] = bitcast <2 x i64> [[X:%.*]] to <4 x i32>
1740+
; CHECK-NEXT: [[Y_BC:%.*]] = bitcast <4 x i32> [[Y:%.*]] to <2 x i64>
1741+
; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i64> [[X]], [[Y_BC]]
1742+
; CHECK-NEXT: [[SUB_BC:%.*]] = bitcast <2 x i64> [[SUB]] to <4 x i32>
1743+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i32> [[Y]], [[X_BC]]
1744+
; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP]], <4 x i32> [[SUB_BC]], <4 x i32> zeroinitializer
1745+
; CHECK-NEXT: ret <4 x i32> [[SEL]]
17411746
;
17421747
%x.bc = bitcast <2 x i64> %x to <4 x i32>
17431748
%y.bc = bitcast <4 x i32> %y to <2 x i64>

0 commit comments

Comments
 (0)