Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Standalone View
llvm/test/Transforms/InstSimplify/rem.ll
Show First 20 Lines • Show All 482 Lines • ▼ Show 20 Lines | |||||
; CHECK-NEXT: [[MOD:%.*]] = urem i8 [[MUL]], [[Y]] | ; CHECK-NEXT: [[MOD:%.*]] = urem i8 [[MUL]], [[Y]] | ||||
; CHECK-NEXT: ret i8 [[MOD]] | ; CHECK-NEXT: ret i8 [[MOD]] | ||||
; | ; | ||||
%d = sdiv i8 %x, %y | %d = sdiv i8 %x, %y | ||||
%mul = mul i8 %y, %d | %mul = mul i8 %y, %d | ||||
%mod = urem i8 %mul, %y | %mod = urem i8 %mul, %y | ||||
ret i8 %mod | ret i8 %mod | ||||
} | } | ||||
define i8 @urem_shl(i8 %x){ | |||||
; CHECK-LABEL: @urem_shl( | |||||
; CHECK-NEXT: ret i8 0 | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl nuw i8 %x, 2 | |||||
%1 = urem i8 %x2, %x1 | |||||
ret i8 %1 | |||||
} | |||||
define i8 @urem_shl_2(i8 %x){ | |||||
david-arm: Could you leave comments on the negative tests explaining why they fail? If it makes it easier… | |||||
Sure thing, should be simple enough MattDevereau: Sure thing, should be simple enough | |||||
; CHECK-LABEL: @urem_shl_2( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: ret i8 [[X1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl nuw i8 %x, 2 | |||||
%1 = urem i8 %x1, %x2 | |||||
ret i8 %1 | |||||
} | |||||
define i8 @srem_shl(i8 %x){ | |||||
; CHECK-LABEL: @srem_shl( | |||||
; CHECK-NEXT: ret i8 0 | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl nsw i8 %x, 2 | |||||
%1 = srem i8 %x2, %x1 | |||||
ret i8 %1 | |||||
} | |||||
define i8 @srem_shl_2(i8 %x){ | |||||
; CHECK-LABEL: @srem_shl_2( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: ret i8 [[X1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl nsw i8 %x, 2 | |||||
%1 = srem i8 %x1, %x2 | |||||
ret i8 %1 | |||||
} | |||||
; Cannot simplify to ret 0 when larger shift is missing nuw with urem | |||||
define i8 @neg_urem_shl_no_nuw(i8 %x){ | |||||
; CHECK-LABEL: @neg_urem_shl_no_nuw( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: [[X2:%.*]] = shl i8 [[X]], 2 | |||||
; CHECK-NEXT: [[TMP1:%.*]] = urem i8 [[X2]], [[X1]] | |||||
Is it worth having a negative test for srem with nuw shifts as well? We shouldn't do any simplification in that case either. david-arm: Is it worth having a negative test for `srem` with `nuw` shifts as well? We shouldn't do any… | |||||
I personally think the current tests are ok since we have one test for nsw which is testing the presence of nsw, and one which tests for it's absence and other flags aren't particularly relevant. These tests are quite compact though so I suppose there's no harm in adding extra cases. MattDevereau: I personally think the current tests are ok since we have one test for nsw which is testing the… | |||||
Sure, I was just thinking that specifically we don't want to perform the simplification for any of nsw or nuw. They both mark the instruction as not wrapping, but only the signed version applies here. It's just because your logic accepts both nsw and nuw flags as valid, but *only if* the signedness matches the instruction. I was hoping to defend against someone accidentally rewriting your code in future and losing the signedness checks. david-arm: Sure, I was just thinking that specifically we don't want to perform the simplification for any… | |||||
I've added negative tests for urem with nsw and srem with nuw now. MattDevereau: I've added negative tests for urem with nsw and srem with nuw now. | |||||
; CHECK-NEXT: ret i8 [[TMP1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl i8 %x, 2 | |||||
%1 = urem i8 %x2, %x1 | |||||
ret i8 %1 | |||||
} | |||||
; Cannot simplify to ret %x1 when larger shift is missing nuw with urem | |||||
define i8 @neg_urem_shl_no_nuw_2(i8 %x){ | |||||
; CHECK-LABEL: @neg_urem_shl_no_nuw_2( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: [[X2:%.*]] = shl i8 [[X]], 2 | |||||
; CHECK-NEXT: [[TMP1:%.*]] = urem i8 [[X1]], [[X2]] | |||||
; CHECK-NEXT: ret i8 [[TMP1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl i8 %x, 2 | |||||
%1 = urem i8 %x1, %x2 | |||||
ret i8 %1 | |||||
} | |||||
; Cannot simplify to ret 0 when larger shift is missing nuw with urem; ignore nsw | |||||
define i8 @neg_urem_shl_no_nuw_3(i8 %x){ | |||||
; CHECK-LABEL: @neg_urem_shl_no_nuw_3( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: [[X2:%.*]] = shl nsw i8 [[X]], 2 | |||||
; CHECK-NEXT: [[TMP1:%.*]] = urem i8 [[X2]], [[X1]] | |||||
; CHECK-NEXT: ret i8 [[TMP1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl nsw i8 %x, 2 | |||||
%1 = urem i8 %x2, %x1 | |||||
ret i8 %1 | |||||
} | |||||
; Cannot simplify to ret 0 when larger shift is missing nsw with srem | |||||
define i8 @neg_srem_shl_no_nsw(i8 %x){ | |||||
; CHECK-LABEL: @neg_srem_shl_no_nsw( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: [[X2:%.*]] = shl i8 [[X]], 2 | |||||
; CHECK-NEXT: [[TMP1:%.*]] = srem i8 [[X2]], [[X1]] | |||||
; CHECK-NEXT: ret i8 [[TMP1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl i8 %x, 2 | |||||
%1 = srem i8 %x2, %x1 | |||||
ret i8 %1 | |||||
} | |||||
; Cannot simplify to ret %x1 when larger shift is missing nsw with srem | |||||
define i8 @neg_srem_shl_no_nsw_2(i8 %x){ | |||||
; CHECK-LABEL: @neg_srem_shl_no_nsw_2( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: [[X2:%.*]] = shl i8 [[X]], 2 | |||||
; CHECK-NEXT: [[TMP1:%.*]] = srem i8 [[X1]], [[X2]] | |||||
; CHECK-NEXT: ret i8 [[TMP1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl i8 %x, 2 | |||||
%1 = srem i8 %x1, %x2 | |||||
ret i8 %1 | |||||
} | |||||
; Cannot simplify to ret 0 when larger shift is missing nsw with srem; ignore nuw | |||||
define i8 @neg_srem_shl_no_nsw_3(i8 %x){ | |||||
; CHECK-LABEL: @neg_srem_shl_no_nsw_3( | |||||
; CHECK-NEXT: [[X1:%.*]] = shl i8 [[X:%.*]], 1 | |||||
; CHECK-NEXT: [[X2:%.*]] = shl nuw i8 [[X]], 2 | |||||
; CHECK-NEXT: [[TMP1:%.*]] = srem i8 [[X2]], [[X1]] | |||||
; CHECK-NEXT: ret i8 [[TMP1]] | |||||
; | |||||
%x1 = shl i8 %x, 1 | |||||
%x2 = shl nuw i8 %x, 2 | |||||
%1 = srem i8 %x2, %x1 | |||||
ret i8 %1 | |||||
} |
Could you leave comments on the negative tests explaining why they fail? If it makes it easier you could put all the negative tests together?