Skip to content

Commit dfb0241

Browse files
vmustyaigcbot
authored andcommitted
Fix GEP lowering pass in VC
The `ptrtoint` folding function should take care of `<1 x ptr>` bitcast to and from `ptr`.
1 parent ddf79c8 commit dfb0241

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXGEPLowering.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ Value *GenXGEPLowering::visitPtrToIntInst(PtrToIntInst &PTI) {
137137
// The `addrspacecast` is just no-op so it can be eliminated
138138
Src = Cast->getOperand(0);
139139
} else if (isa<BitCastInst>(Cast)) {
140+
auto *Arg = Cast->getOperand(0);
141+
auto *ArgTy = Arg->getType();
142+
auto *CastTy = Cast->getType();
143+
if (ArgTy->isVectorTy() != CastTy->isVectorTy())
144+
break;
140145
// The `bitcast` is just no-op so it can be eliminated
141-
Src = Cast->getOperand(0);
146+
Src = Arg;
142147
} else {
143148
// We found `inttoptr`, getting rid of `ptrtoint`
144149
if (isa<IntToPtrInst>(Cast))

IGC/VectorCompiler/test/GenXGEPLowering/fold-ptrtoint.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,14 @@ label: ; preds = %entry
6363
%splat = shufflevector <16 x i64> %ins, <16 x i64> undef, <16 x i32> zeroinitializer
6464
ret void
6565
}
66+
67+
; CHECK-LABEL: @test_bitcast_vector_to_scalar
68+
define i64 @test_bitcast_vector_to_scalar(<1 x i8*> %vptr) {
69+
%ptr = bitcast <1 x i8*> %vptr to i8*
70+
%gep = getelementptr i8, i8* %ptr, i32 123
71+
%addr = ptrtoint i8* %gep to i64
72+
; CHECK: [[PTI:%[^ ]+]] = ptrtoint i8* %ptr to i64
73+
; CHECK: [[ADD:%[^ ]+]] = add i64 [[PTI]], 123
74+
; CHECK: ret i64 [[ADD]]
75+
ret i64 %addr
76+
}

0 commit comments

Comments
 (0)