llvm.org GIT mirror llvm / 789efba
Fix constant folding through bitcasts by no longer relying on undefined behaviour (converting NaN values between float and double). SelectionDAG::getConstantFP(double Val, EVT VT, bool isTarget); should not be used when Val is not a simple constant (as the comment in SelectionDAG.h indicates). This patch avoids using this function when folding an unknown constant through a bitcast, where it cannot be guaranteed that Val will be a simple constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163703 91177308-0d34-0410-b5e6-96231b3b80d8 Kristof Beyls 7 years ago
2 changed file(s) with 12 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
24532453 }
24542454 case ISD::BITCAST:
24552455 if (VT == MVT::f32 && C->getValueType(0) == MVT::i32)
2456 return getConstantFP(Val.bitsToFloat(), VT);
2456 return getConstantFP(APFloat(Val), VT);
24572457 else if (VT == MVT::f64 && C->getValueType(0) == MVT::i64)
2458 return getConstantFP(Val.bitsToDouble(), VT);
2458 return getConstantFP(APFloat(Val), VT);
24592459 break;
24602460 case ISD::BSWAP:
24612461 return getConstant(Val.byteSwap(), VT);
4444 ret void
4545 }
4646
47 define i32 @f8() nounwind {
48 ; Check that constant propagation through (i32)-1 => (float)Nan => (i32)-1
49 ; gives expected result
50 ; CHECK: f8
51 ; CHECK: mvn r0, #0
52 %tmp0 = bitcast i32 -1 to float
53 %tmp1 = bitcast float %tmp0 to i32
54 ret i32 %tmp1
55 }
56
4757 %t1 = type { <3 x float>, <3 x float> }
4858
4959 @const1 = global %t1 { <3 x float> zeroinitializer,