llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
307 stars 84 forks source link

[CIR][NFC] Fix bug during fp16 unary op CIRGen #706

Closed Lancern closed 2 days ago

Lancern commented 5 days ago

This PR fixes a bug during the CIRGen of fp16 unary operations. Before this patch, for the expression -x where x is a fp16 value, CIRGen emits the code like the following:

%0 = cir.cast float_to_float %x : !cir.f16 -> !cir.float
%1 = cir.cast float_to_float %0 : !cir.float -> !cir.f16
%2 = cir.unary minus %1 : !cir.fp16

The expected CIRGen should instead be:

%0 = cir.cast float_to_float %x : !cir.f16 -> !cir.float
%1 = cir.unary minus %0 : !cir.float
%2 = cir.cast float_to_float %1 : !cir.float -> !cir.f16

This PR fixes this issue.