Files
clang-p2996/clang/test/CodeGen/constantexpr-fneg.c
Nikita Popov 3b25407d97 [IR] Mark zext/sext constant expressions as undesirable
Introduce isDesirableCastOp() which determines whether IR builder
and constant folding should produce constant expressions for a
given cast type. This mirrors what we do for binary operators.

Mark zext/sext as undesirable, which prevents most creations of such
constant expressions. This is still somewhat incomplete and there
are a few more places that can create zext/sext expressions.

This is part of the work for
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.

The reason for the odd result in the constantexpr-fneg.c test is
that initially the "a[]" global is created with an [0 x i32] type,
at which point the icmp expression cannot be folded. Later it is
replaced with an [1 x i32] global and the icmp gets folded away.
But at that point we no longer fold the zext.
2023-10-02 12:40:20 +02:00

24 lines
819 B
C

// RUN: %clang_cc1 -emit-llvm-bc -disable-llvm-passes -o %t.bc %s
// 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-LABEL define i32 @main()
// CHECK: entry:
// CHECK-NEXT: %retval = alloca i32
// CHECK-NEXT: store i32 0, ptr %retval
// CHECK-NEXT: [[ZEXT:%.*]] = zext i1 true to i32
// CHECK-NEXT: [[SITOFP:%.*]] = sitofp i32 [[ZEXT]] to float
// CHECK-NEXT: [[LV:%.*]] = load ptr, ptr @c
// CHECK-NEXT: store float [[SITOFP]], ptr [[LV]], align 4
// CHECK-NEXT: [[FNEG:%.*]] = fneg float [[SITOFP]]
// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[FNEG]] to i32
// CHECK-NEXT: ret i32 [[CONV]]
int a[], b;
float *c;
int main(void) {
return -(*c = &b != a);
}