-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR][CIRGen] Support __builtin_isinf_sign
This patch adds support for `__builtin_isinf_sign`. The implementation has several limitations that result in discrepancies between the generated LLVM IR and the expected output. Firstly, it uses `IsFPClass` to determine if a value is infinite, whereas the original CGBuiltin implementation used direct comparisons with infinity constants. Secondly, due to #480, there are numerous unnecessary type conversions occurring, such as converting from i1 to i8 and then back to i1. Additionally, `SignBitOp` cannot set the return type to `CIR_BoolType`, as doing so would lead to failures during the lowering to LLVM IR.
- Loading branch information
1 parent
da601b3
commit d0f75b4
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll | ||
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s | ||
|
||
int test_float_isinf_sign(float x) { | ||
// CIR-LABEL: test_float_isinf_sign | ||
// CIR: %[[TMP0:.*]] = cir.load %{{.*}} : !cir.ptr<!cir.float>, !cir.float | ||
// CIR: %[[IS_INF:.*]] = cir.is_fp_class %[[TMP0]], 516 : (!cir.float) -> !cir.bool | ||
// CIR: %[[TMP1:.*]] = cir.signbit %[[TMP0]] : !cir.float -> !s32i | ||
// CIR: %[[IS_NEG:.*]] = cir.cast(int_to_bool, %[[TMP1]] : !s32i), !cir.bool | ||
// CIR: %[[C_0:.*]] = cir.const #cir.int<0> : !s32i | ||
// CIR: %[[C_1:.*]] = cir.const #cir.int<1> : !s32i | ||
// CIR: %[[C_m1:.*]] = cir.const #cir.int<-1> : !s32i | ||
// CIR: %[[TMP4:.*]] = cir.select if %[[IS_NEG]] then %[[C_m1]] else %[[C_1]] : (!cir.bool, !s32i, !s32i) -> !s32i | ||
// CIR: %10 = cir.select if %[[IS_INF]] then %[[TMP4]] else %[[C_0]] : (!cir.bool, !s32i, !s32i) -> !s32i | ||
|
||
// LLVM-LABEL: test_float_isinf_sign | ||
// LLVM: %[[TMP0:.*]] = load float, ptr %{{.*}} | ||
// LLVM: %[[IS_INF:.*]] = call i1 @llvm.is.fpclass.f32(float %[[TMP0]], i32 516) | ||
// LLVM: %[[IS_INF_I8:.*]] = zext i1 %[[IS_INF]] to i8 | ||
// LLVM: %[[TMP1:.*]] = bitcast float %[[TMP0]] to i32 | ||
// LLVM: %[[IS_NEG:.*]] = icmp slt i32 %[[TMP1]], 0 | ||
// FIXME: eliminate the redundant instruction | ||
// [[IS_NEG]] changes bool -> i8 -> i32 -> i1 | ||
// LLVM: %[[TMP2:.*]] = select i1 %{{.*}}, i32 -1, i32 1 | ||
// LLVM: %[[IS_INF_I1:.*]] = trunc i8 %[[IS_INF_I8]] to i1 | ||
// LLVM: %{{.*}} = select i1 %[[IS_INF_I1]], i32 %[[TMP2]], i32 0 | ||
return __builtin_isinf_sign(x); | ||
} |