Skip to content

Commit

Permalink
[InstSimplify] Consider bitcast as potential cross-lane operation
Browse files Browse the repository at this point in the history
The bitcast might change the number of vector lanes, in which case
it will be a cross-lane operation.

Fixes llvm#77320.
  • Loading branch information
nikic committed Jan 8, 2024
1 parent ade7ae4 commit 97e3220
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4313,7 +4313,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
// For vector types, the simplification must hold per-lane, so forbid
// potentially cross-lane operations like shufflevector.
if (!I->getType()->isVectorTy() || isa<ShuffleVectorInst>(I) ||
isa<CallBase>(I))
isa<CallBase>(I) || isa<BitCastInst>(I))
return nullptr;
}

Expand Down
9 changes: 7 additions & 2 deletions llvm/test/Transforms/InstSimplify/select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1734,10 +1734,15 @@ define i8 @select_or_disjoint_eq(i8 %x, i8 %y) {
ret i8 %sel
}

; FIXME: This is a miscompile.
define <4 x i32> @select_vector_cmp_with_bitcasts(<2 x i64> %x, <4 x i32> %y) {
; CHECK-LABEL: @select_vector_cmp_with_bitcasts(
; CHECK-NEXT: ret <4 x i32> zeroinitializer
; CHECK-NEXT: [[X_BC:%.*]] = bitcast <2 x i64> [[X:%.*]] to <4 x i32>
; CHECK-NEXT: [[Y_BC:%.*]] = bitcast <4 x i32> [[Y:%.*]] to <2 x i64>
; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i64> [[X]], [[Y_BC]]
; CHECK-NEXT: [[SUB_BC:%.*]] = bitcast <2 x i64> [[SUB]] to <4 x i32>
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i32> [[Y]], [[X_BC]]
; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP]], <4 x i32> [[SUB_BC]], <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x i32> [[SEL]]
;
%x.bc = bitcast <2 x i64> %x to <4 x i32>
%y.bc = bitcast <4 x i32> %y to <2 x i64>
Expand Down

0 comments on commit 97e3220

Please sign in to comment.