Skip to content

Commit b98a2ba

Browse files
esukhovigcbot
authored andcommitted
Only Rematerialize ptr bitcasts for function calls inside
CloneAddressArithmetic Only Rematerialize ptr bitcasts for function calls inside CloneAddressArithmetic
1 parent 92d6114 commit b98a2ba

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

IGC/Compiler/CISACodeGen/RematAddressArithmetic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ bool isRematInstruction(llvm::Value* V) {
515515

516516
bool IntToPtr = llvm::isa<IntToPtrInst>(V);
517517
bool AddrSpCast = llvm::isa<AddrSpaceCastInst>(V);
518-
bool BitCast = llvm::isa<BitCastInst>(V);
518+
// use only bitcasts on pointers as a seed instruction
519+
bool BitCast = llvm::isa<BitCastInst>(V) && V->getType()->isPointerTy();
519520
bool GEP = llvm::isa<GetElementPtrInst>(V);
520521

521522
bool Result = IntToPtr || AddrSpCast || BitCast || GEP;
@@ -530,6 +531,7 @@ void CloneAddressArithmetic::collectInstToProcess(RematSet& ToProcess, Function&
530531
bool IsLoad = llvm::isa<LoadInst>(I);
531532
bool IsStore = llvm::isa<StoreInst>(I);
532533
bool IsCall = llvm::isa<CallInst>(I);
534+
533535
if (!IsLoad && !IsStore && !IsCall) continue;
534536

535537
llvm::Value* V =

IGC/Compiler/tests/RematAddressArithmetic/callParametarsRemat.ll renamed to IGC/Compiler/tests/RematAddressArithmetic/callParametersRemat.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ target triple = "spir64-unknown-unknown"
1717
%struct.packed_float3 = type { float, float, float }
1818

1919
declare spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)*)
20+
declare spir_func void @target_func_bitcast_no_ptr(double)
2021

2122
define spir_kernel void @main() {
2223
entry:
@@ -34,3 +35,31 @@ cleanup.cont.i: ; preds = %if.end46
3435
call spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)* %ls.ascast.i)
3536
ret void
3637
}
38+
39+
define spir_func void @bar(i64 %arg1) {
40+
entry:
41+
%val2 = mul i64 %arg1, 2
42+
%val3 = mul i64 %arg1, 3
43+
%cast_val2 = bitcast i64 %val2 to double
44+
%cast_val3 = bitcast i64 %val3 to double
45+
; CHECK: [[VAL2:%.*]] = mul i64 [[ARG1:%.*]], 2
46+
; CHECK: [[VAL3:%.*]] = mul i64 [[ARG1]], 3
47+
; CHECK: bitcast i64 [[VAL2]] to double
48+
; CHECK: bitcast i64 [[VAL3]] to double
49+
; CHECK: br label %if.end46
50+
%ls.i = alloca %"struct.ONEAPIKernelContext::LightSample", i32 0, align 4
51+
br label %if.end46
52+
53+
if.end46:
54+
%ls.ascast.i = addrspacecast %"struct.ONEAPIKernelContext::LightSample"* %ls.i to %"struct.ONEAPIKernelContext::LightSample" addrspace(4)*
55+
br label %cleanup.cont.i
56+
; CHECK-LABEL: cleanup.cont.i:
57+
; CHECK-NEXT: [[REMAT:%.*]] = alloca %"struct.ONEAPIKernelContext::LightSample", i32 0, align 4
58+
; CHECK-NEXT: [[CAST:%.*]] = addrspacecast %"struct.ONEAPIKernelContext::LightSample"* [[REMAT]] to %"struct.ONEAPIKernelContext::LightSample" addrspace(4)*
59+
; CHECK-NEXT: call spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)* [[CAST]])
60+
cleanup.cont.i: ; preds = %if.end46
61+
call spir_func void @target_func(%"struct.ONEAPIKernelContext::LightSample" addrspace(4)* %ls.ascast.i)
62+
call spir_func void @target_func_bitcast_no_ptr(double %cast_val2)
63+
call spir_func void @target_func_bitcast_no_ptr(double %cast_val3)
64+
ret void
65+
}

IGC/Compiler/tests/RematAddressArithmetic/cloneAddressArithmetic.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,32 @@ define spir_kernel void @main(double addrspace(1)* %base, i64 %offset, i64 %I, i
3434
store double %rr0, double addrspace(1)* %a4
3535
ret void
3636
}
37+
38+
39+
define spir_func void @bar(double addrspace(1)* %base, i64 %offset, i64 %I, i64 %J) {
40+
41+
; CHECK: define spir_func void @bar(double addrspace(1)* [[BASE:%.*]], i64 [[OFFSET:%.*]], i64 %I, i64 %J)
42+
43+
%baseArith = ptrtoint double addrspace(1)* %base to i64
44+
; CHECK: [[FIRSTBASE:%.*]] = ptrtoint double addrspace(1)* [[BASE]] to i64
45+
; CHECK: [[FIRSTOFFSET:%.*]] = mul nuw nsw i64 [[OFFSET]], 207368
46+
%basePtr = mul nuw nsw i64 %offset, 207368
47+
%offsetI = mul nsw i64 %I, 1288
48+
%offsetJ = shl nsw i64 %J, 3
49+
50+
%a0 = add i64 %baseArith, 100780848
51+
%a1 = add i64 %a0, %basePtr
52+
%a2 = add i64 %a1, %offsetI
53+
%a3 = add i64 %a2, %offsetJ
54+
%a4 = inttoptr i64 %a3 to double addrspace(1)*
55+
%a5 = inttoptr i64 %a3 to i64 addrspace(1)*
56+
%r0 = load double, double addrspace(1)* %a4, align 8
57+
58+
%rr0 = fmul double %r0, 2.0
59+
60+
; CHECK: [[SECONDBASE:%.*]] = ptrtoint double addrspace(1)* [[BASE]] to i64
61+
; CHECK: [[SECONDOFFSET:%.*]] = mul nuw nsw i64 [[OFFSET]], 207368
62+
%cast_a5 = bitcast i64 addrspace(1)* %a5 to double addrspace(1)*
63+
store double %rr0, double addrspace(1)* %cast_a5
64+
ret void
65+
}

0 commit comments

Comments
 (0)