<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div><div><div class=""></div></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><br class="">The existing behavior pins to infinity or a max int value, but that may just<br class="">lead to more confusion as seen in:<br class=""><a href="http://llvm.org/bugs/show_bug.cgi?id=21130" class="">http://llvm.org/bugs/show_bug.cgi?id=21130</a><br class=""><br class="">Returning undef will hopefully lead to a less silent failure.<br class=""><br class="">Differential Revision: http://reviews.llvm.org/D5603<br class=""><br class=""><br class="">Modified:<br class=""> llvm/trunk/lib/IR/ConstantFold.cpp<br class=""> llvm/trunk/test/Transforms/InstCombine/cast.ll<br class=""><br class="">Modified: llvm/trunk/lib/IR/ConstantFold.cpp<br class="">URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=219542&r1=219541&r2=219542&view=diff<br class="">==============================================================================<br class="">--- llvm/trunk/lib/IR/ConstantFold.cpp (original)<br class="">+++ llvm/trunk/lib/IR/ConstantFold.cpp Fri Oct 10 18:00:21 2014<br class="">@@ -593,8 +593,13 @@ Constant *llvm::ConstantFoldCastInstruct<br class=""> bool ignored;<br class=""> uint64_t x[2]; <br class=""> uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();<br class="">- (void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,<br class="">- APFloat::rmTowardZero, &ignored);<br class="">+ if (APFloat::opInvalidOp ==<br class="">+ V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,<br class="">+ APFloat::rmTowardZero, &ignored)) {<br class="">+ // Undefined behavior invoked - the destination type can't represent<br class="">+ // the input constant.<br class="">+ return UndefValue::get(DestTy);<br class="">+ }<br class=""> APInt Val(DestBitWidth, x);<br class=""> return ConstantInt::get(FPC->getContext(), Val);<br class=""> }<br class="">@@ -653,9 +658,13 @@ Constant *llvm::ConstantFoldCastInstruct<br class=""> APInt api = CI->getValue();<br class=""> APFloat apf(DestTy->getFltSemantics(),<br class=""> APInt::getNullValue(DestTy->getPrimitiveSizeInBits()));<br class="">- (void)apf.convertFromAPInt(api, <br class="">- opc==Instruction::SIToFP,<br class="">- APFloat::rmNearestTiesToEven);<br class="">+ if (APFloat::opOverflow &<br class="">+ apf.convertFromAPInt(api, opc==Instruction::SIToFP,<br class="">+ APFloat::rmNearestTiesToEven)) {<br class="">+ // Undefined behavior invoked - the destination type can't represent<br class="">+ // the input constant.<br class="">+ return UndefValue::get(DestTy);<br class="">+ }<br class=""> return ConstantFP::get(V->getContext(), apf);<br class=""> }<br class=""> return nullptr;<br class=""><br class="">Modified: llvm/trunk/test/Transforms/InstCombine/cast.ll<br class="">URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cast.ll?rev=219542&r1=219541&r2=219542&view=diff<br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/InstCombine/cast.ll (original)<br class="">+++ llvm/trunk/test/Transforms/InstCombine/cast.ll Fri Oct 10 18:00:21 2014<br class="">@@ -1050,3 +1050,37 @@ define i8 @test85(i32 %a) {<br class=""> ; CHECK: [[SHR:%.*]] = lshr exact i32 [[ADD]], 23<br class=""> ; CHECK: [[CST:%.*]] = trunc i32 [[SHR]] to i8<br class=""> }<br class="">+<br class="">+; Overflow on a float to int or int to float conversion is undefined (PR21130).<br class="">+<br class="">+define i8 @overflow_fptosi() {<br class="">+ %i = fptosi double 1.56e+02 to i8<br class="">+ ret i8 %i<br class="">+; CHECK-LABEL: @overflow_fptosi(<br class="">+; CHECK-NEXT: ret i8 undef <br class="">+}<br class="">+<br class="">+define i8 @overflow_fptoui() {<br class="">+ %i = fptoui double 2.56e+02 to i8<br class="">+ ret i8 %i<br class="">+; CHECK-LABEL: @overflow_fptoui(<br class="">+; CHECK-NEXT: ret i8 undef <br class="">+}<br class="">+<br class="">+; The maximum float is approximately 2 ** 128 which is 3.4E38. <br class="">+; The constant below is 4E38. Use a 130 bit integer to hold that<br class="">+; number; 129-bits for the value + 1 bit for the sign.<br class="">+define float @overflow_uitofp() {<br class="">+ %i = uitofp i130 400000000000000000000000000000000000000 to float<br class="">+ ret float %i<br class="">+; CHECK-LABEL: @overflow_uitofp(<br class="">+; CHECK-NEXT: ret float undef <br class="">+}<br class="">+<br class="">+define float @overflow_sitofp() {<br class="">+ %i = sitofp i130 400000000000000000000000000000000000000 to float<br class="">+ ret float %i<br class="">+; CHECK-LABEL: @overflow_sitofp(<br class="">+; CHECK-NEXT: ret float undef <br class="">+}<br class="">+<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class="">llvm-commits@cs.uiuc.edu<br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></body></html>