[PATCH] D21769: [InstCombine] shrink type of sdiv if dividend is sexted and constant divisor is small enough (PR28153)

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 14:55:59 PDT 2016


majnemer added inline comments.

================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:1156
@@ +1155,3 @@
+    // to fit in the source type, shrink the division to the narrower type:
+    // (sext X) sdiv C --> sext (X sdiv C)
+    Value *Op0Src;
----------------
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.


http://reviews.llvm.org/D21769





More information about the llvm-commits mailing list