This is intended to fix PR28153:
https://llvm.org/bugs/show_bug.cgi?id=28153
Details
Diff Detail
Event Timeline
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | ||
---|---|---|
1156 | Say X is i16 -32768 and C is i32 65535, the result of the sdiv will be -32768/65535 which is zero. |
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | ||
---|---|---|
1156 | The code comment may be misleading. Your example won't fold because getMinSignedBits() for 65535 is 17. It may be clearer when you see the limits in the test cases. Any ideas about how to make that code comment more specific? Should I put your example case in there? |
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | ||
---|---|---|
1156 | Sorry if this comment wasn't clear as well. :) |
LGTM
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | ||
---|---|---|
1156 | I missed the MinSignedBits part of your patch, seems fine to me. I think it'd be good to include by testcase. |
Say X is i16 -32768 and C is i32 65535, the result of the sdiv will be -32768/65535 which is zero.
However, trunc of C to i16 is 65535. the result of X sdiv C will be -32768/-1 which is UB because it overflows.