Skip to content

Commit

Permalink
Merged master:cda94d3e8ae into amd-gfx:a78cf91cc1a
Browse files Browse the repository at this point in the history
Local branch amd-gfx a78cf91 Merged master:e2d9f4e6a28 into amd-gfx:1291a95764f
Remote branch master cda94d3 [mlir] Floating constants for import-llvm
  • Loading branch information
Sw authored and Sw committed Dec 27, 2019
2 parents a78cf91 + cda94d3 commit 8545c1f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ Attribute Importer::getConstantAsAttr(llvm::Constant *value) {
if (auto *c = dyn_cast<llvm::ConstantDataArray>(value))
if (c->isString())
return b.getStringAttr(c->getAsString());
if (auto *c = dyn_cast<llvm::ConstantFP>(value)) {
if (c->getType()->isDoubleTy())
return b.getFloatAttr(FloatType::getF64(context), c->getValueAPF());
else if (c->getType()->isFloatingPointTy())
return b.getFloatAttr(FloatType::getF32(context), c->getValueAPF());
}
return Attribute();
}

Expand Down
29 changes: 29 additions & 0 deletions mlir/test/Target/import.ll
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,32 @@ define void @f6(void (i16) *%fn) {
call void %fn(i16 0)
ret void
}

; CHECK-LABEL: llvm.func @FPArithmetic(%arg0: !llvm.float, %arg1: !llvm.float, %arg2: !llvm.double, %arg3: !llvm.double)
define void @FPArithmetic(float %a, float %b, double %c, double %d) {
; CHECK: %[[a1:[0-9]+]] = llvm.mlir.constant(3.030000e+01 : f64) : !llvm.double
; CHECK: %[[a2:[0-9]+]] = llvm.mlir.constant(3.030000e+01 : f32) : !llvm.float
; CHECK: %[[a3:[0-9]+]] = llvm.fadd %[[a2]], %arg0 : !llvm.float
%1 = fadd float 0x403E4CCCC0000000, %a
; CHECK: %[[a4:[0-9]+]] = llvm.fadd %arg0, %arg1 : !llvm.float
%2 = fadd float %a, %b
; CHECK: %[[a5:[0-9]+]] = llvm.fadd %[[a1]], %arg2 : !llvm.double
%3 = fadd double 3.030000e+01, %c
; CHECK: %[[a6:[0-9]+]] = llvm.fsub %arg0, %arg1 : !llvm.float
%4 = fsub float %a, %b
; CHECK: %[[a7:[0-9]+]] = llvm.fsub %arg2, %arg3 : !llvm.double
%5 = fsub double %c, %d
; CHECK: %[[a8:[0-9]+]] = llvm.fmul %arg0, %arg1 : !llvm.float
%6 = fmul float %a, %b
; CHECK: %[[a9:[0-9]+]] = llvm.fmul %arg2, %arg3 : !llvm.double
%7 = fmul double %c, %d
; CHECK: %[[a10:[0-9]+]] = llvm.fdiv %arg0, %arg1 : !llvm.float
%8 = fdiv float %a, %b
; CHECK: %[[a12:[0-9]+]] = llvm.fdiv %arg2, %arg3 : !llvm.double
%9 = fdiv double %c, %d
; CHECK: %[[a11:[0-9]+]] = llvm.frem %arg0, %arg1 : !llvm.float
%10 = frem float %a, %b
; CHECK: %[[a13:[0-9]+]] = llvm.frem %arg2, %arg3 : !llvm.double
%11 = frem double %c, %d
ret void
}

0 comments on commit 8545c1f

Please sign in to comment.