Skip to content

Commit

Permalink
Removeing dead code
Browse files Browse the repository at this point in the history
Couldn't produce a test to hit removed code. The maximum (power of 2) value you can store in any iXX variable is 2^XX-1. The 2^XX can't fit into iXX
  • Loading branch information
krzysiek358 authored and igcbot committed Sep 19, 2024
1 parent 5c788e5 commit 5089830
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 2 additions & 5 deletions IGC/Compiler/Optimizer/IntDivConstantReduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,8 @@ struct IntDivConstantReduction : public FunctionPass
int shiftAmt = divisor.logBase2();
Value *result;
if (isMod) {
if (shiftAmt == bitSize) { // X % MAX_VAL = X
result = dividend;
} else { // X % 2^K = (X & ((1<<K)-1))
result = B.CreateAnd(dividend, ((1ull << shiftAmt)-1));
}
// X % 2^K = (X & ((1<<K)-1))
result = B.CreateAnd(dividend, ((1ull << shiftAmt)-1));
} else {
result = B.CreateLShr(dividend, shiftAmt);
}
Expand Down
11 changes: 11 additions & 0 deletions IGC/Compiler/tests/IntDivConstantReduction/basic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ define spir_kernel void @test_sdiv_max(i32 %src1) {
ret void
}

define spir_kernel void @test_rem_pow_of_2(i32 %src1) {
; CHECK-LABEL: @test_rem_pow_of_2(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[SRC1:%.*]], 2147483647
; CHECK-NEXT: call void @use.i32(i32 [[TMP1]])
; CHECK-NEXT: ret void
;
%1 = urem i32 %src1, 2147483648 ; <- 2^31
call void @use.i32(i32 %1)
ret void
}

define spir_kernel void @test_udiv_max(i32 %src1) {
; CHECK-LABEL: @test_udiv_max(
; CHECK: [[Q_APPX:%.*]] = call i32 @llvm.genx.GenISA.umulH.i32(i32 %src1, i32 -2147483647)
Expand Down

0 comments on commit 5089830

Please sign in to comment.