// RUN: llvm-dis %t.bc -o - | FileCheck %s
// Test case for PR45426. Make sure we do not crash while writing bitcode
-// containing a simplify-able fneg constant expression. Check that the created
-// bitcode file can be disassembled and has the constant expressions simplified.
+// containing a simplify-able fneg constant expression.
//
// CHECK-LABEL define i32 @main()
// CHECK: entry:
// CHECK-NEXT: store i32 0, i32* %retval
// CHECK-NEXT: [[LV:%.*]] = load float*, float** @c
// CHECK-NEXT: store float 1.000000e+00, float* [[LV]], align 4
-// CHECK-NEXT: ret i32 -1
+// CHECK-NEXT: [[FNEG:%.*]] = fneg float 1.000000e+00
+// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[FNEG]] to i32
+// CHECK-NEXT: ret i32 [[CONV]]
int a[], b;
float *c;
Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
FastMathFlags FMF) const override {
if (Constant *C = dyn_cast<Constant>(V))
- return Fold(ConstantExpr::get(Opc, C));
+ return ConstantFoldUnaryOpOperand(Opc, C, DL);
return nullptr;
}
Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
FastMathFlags FMF) const override {
if (Constant *C = dyn_cast<Constant>(V))
- return ConstantExpr::get(Opc, C);
+ return ConstantFoldUnaryInstruction(Opc, C);
return nullptr;
}
const DataLayout &DL) {
assert(Instruction::isUnaryOp(Opcode));
- return ConstantExpr::get(Opcode, Op);
+ return ConstantFoldUnaryInstruction(Opcode, Op);
}
Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS,
define double @fmul_negated_constant_expression(double %x) {
; CHECK-LABEL: @fmul_negated_constant_expression(
-; CHECK-NEXT: [[R:%.*]] = fmul double [[X:%.*]], fneg (double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double))
+; CHECK-NEXT: [[FSUB:%.*]] = fneg double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double)
+; CHECK-NEXT: [[R:%.*]] = fmul double [[FSUB]], [[X:%.*]]
; CHECK-NEXT: ret double [[R]]
;
%fsub = fsub double -0.000000e+00, bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double)
define float @fneg_nsz_fadd_constant_expr(float %x) {
; CHECK-LABEL: @fneg_nsz_fadd_constant_expr(
-; CHECK-NEXT: [[R:%.*]] = fsub nsz float fneg (float bitcast (i32 ptrtoint (i16* @g to i32) to float)), [[X:%.*]]
+; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], bitcast (i32 ptrtoint (i16* @g to i32) to float)
+; CHECK-NEXT: [[R:%.*]] = fneg nsz float [[A]]
; CHECK-NEXT: ret float [[R]]
;
%a = fadd float %x, bitcast (i32 ptrtoint (i16* @g to i32) to float)
define float @fake_fneg_nsz_fadd_constant_expr(float %x) {
; CHECK-LABEL: @fake_fneg_nsz_fadd_constant_expr(
-; CHECK-NEXT: [[R:%.*]] = fsub nsz float fneg (float bitcast (i32 ptrtoint (i16* @g to i32) to float)), [[X:%.*]]
+; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], bitcast (i32 ptrtoint (i16* @g to i32) to float)
+; CHECK-NEXT: [[R:%.*]] = fneg nsz float [[A]]
; CHECK-NEXT: ret float [[R]]
;
%a = fadd float %x, bitcast (i32 ptrtoint (i16* @g to i32) to float)
define float @undef1() {
; CHECK-LABEL: @undef1(
-; CHECK-NEXT: ret float 0.000000e+00
+; CHECK-NEXT: [[FACTOR1:%.*]] = fmul fast float -1.000000e+00, bitcast (i32 ptrtoint (i32* @g to i32) to float)
+; CHECK-NEXT: [[REASS_ADD:%.*]] = fadd fast float [[FACTOR1]], bitcast (i32 ptrtoint (i32* @g to i32) to float)
+; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], 2.000000e+00
+; CHECK-NEXT: ret float [[REASS_MUL]]
;
%t0 = fadd fast float bitcast (i32 ptrtoint (i32* @g to i32) to float), bitcast (i32 ptrtoint (i32* @g to i32) to float)
%t1 = fsub fast float bitcast (i32 ptrtoint (i32* @g to i32) to float), %t0