i8 and i16 are not using overflow.
Reduce the number of zero extension instructions.
To reduce the uncertainty of the unknown,
most of the checks of the virtual function are kept
Differential D143646
[RISCV] Return false from shouldFormOverflowOp when type is i8 and i16 liaolucy on Feb 9 2023, 6:45 AM. Authored by
Details i8 and i16 are not using overflow. To reduce the uncertainty of the unknown,
Diff Detail
Event TimelineComment Actions The regression in D142071 was for i64 on rv32. Do we need to disable this completely or only for that case?
Comment Actions Solving the regression of uaddo1_math_overflow_used. the regression testcase. define i64 @uaddo1_math_overflow_used(i64 %a, i64 %b, ptr %res) nounwind ssp { %add = add i64 %b, %a %cmp = icmp ult i64 %add, %a ----------%a %Q = select i1 %cmp, i64 %b, i64 42 store i64 %add, ptr %res ret i64 %Q } No regression, the testcase from the following of file define i64 @uaddo2_math_overflow_used(i64 %a, i64 %b, ptr %res) nounwind ssp { %add = add i64 %b, %a %cmp = icmp ult i64 %add, %b -----------%b %Q = select i1 %cmp, i64 %b, i64 42 store i64 %add, ptr %res ret i64 %Q } So I think it is good to modify it to: define i64 @uaddo1_math_overflow_used(i64 %a, i64 %b, ptr %res) nounwind ssp { %add = add i64 %a, %b --------a and b exchange positions %cmp = icmp ult i64 %add, %a %Q = select i1 %cmp, i64 %b, i64 42 store i64 %add, ptr %res ret i64 %Q }
Comment Actions A+B u< A is the same result as A+B u< B. Comment Actions I found that i8 and i16 are better without overflow, so I kept it here and returned false when the data type is i8 and i16 overflow promote, LHS and RHS use ZExtPromotedInteger in PromoteIntRes_UADDSUBO. Comment Actions I'm not sure the tests are here are sufficient to motivate this change. They "noncanonical" having the 1 on the LHS of an add instead of the RHS. And they only test the +1 case. Does shouldFormOverflowOp only apply to +1? Comment Actions Add a testcase where both the LHS and RHS are not immediate, and it reduces one 'and' instruction.
Comment Actions Address craig.topper's comments. |
What if we did
That would match how you've described this patch.