Skip to content

Commit 2a08285

Browse files
author
Aditya Nandakumar
committed
Revert "Revert r339977: [GISel]: Add Opcodes for a few LLVM Intrinsics"
This reverts commit 7debc33. I missed updating legalizer-info-validation.mir as I had assertions turned off in my build and that specific test requires asserts. Fixed it now. llvm-svn: 340197
1 parent 6ac9059 commit 2a08285

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

llvm/include/llvm/Support/TargetOpcodes.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ HANDLE_TARGET_OPCODE(G_INTTOPTR)
268268
/// COPY is the relevant instruction.
269269
HANDLE_TARGET_OPCODE(G_BITCAST)
270270

271+
/// INTRINSIC trunc intrinsic.
272+
HANDLE_TARGET_OPCODE(G_INTRINSIC_TRUNC)
273+
274+
/// INTRINSIC round intrinsic.
275+
HANDLE_TARGET_OPCODE(G_INTRINSIC_ROUND)
276+
271277
/// Generic load (including anyext load)
272278
HANDLE_TARGET_OPCODE(G_LOAD)
273279

llvm/include/llvm/Target/GenericOpcodes.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,21 @@ def G_FLOG2 : GenericInstruction {
512512
let hasSideEffects = 0;
513513
}
514514

515+
//------------------------------------------------------------------------------
516+
// Opcodes for LLVM Intrinsics
517+
//------------------------------------------------------------------------------
518+
def G_INTRINSIC_TRUNC : GenericInstruction {
519+
let OutOperandList = (outs type0:$dst);
520+
let InOperandList = (ins type0:$src1);
521+
let hasSideEffects = 0;
522+
}
523+
524+
def G_INTRINSIC_ROUND : GenericInstruction {
525+
let OutOperandList = (outs type0:$dst);
526+
let InOperandList = (ins type0:$src1);
527+
let hasSideEffects = 0;
528+
}
529+
515530
//------------------------------------------------------------------------------
516531
// Memory ops
517532
//------------------------------------------------------------------------------

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,16 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
861861
.addDef(getOrCreateVReg(CI))
862862
.addUse(getOrCreateVReg(*CI.getArgOperand(0)));
863863
return true;
864+
case Intrinsic::trunc:
865+
MIRBuilder.buildInstr(TargetOpcode::G_INTRINSIC_TRUNC)
866+
.addDef(getOrCreateVReg(CI))
867+
.addUse(getOrCreateVReg(*CI.getArgOperand(0)));
868+
return true;
869+
case Intrinsic::round:
870+
MIRBuilder.buildInstr(TargetOpcode::G_INTRINSIC_ROUND)
871+
.addDef(getOrCreateVReg(CI))
872+
.addUse(getOrCreateVReg(*CI.getArgOperand(0)));
873+
return true;
864874
case Intrinsic::fma:
865875
MIRBuilder.buildInstr(TargetOpcode::G_FMA)
866876
.addDef(getOrCreateVReg(CI))

llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,26 @@ define float @test_fabs_intrin(float %a) {
14081408
ret float %res
14091409
}
14101410

1411+
declare float @llvm.trunc.f32(float)
1412+
define float @test_intrinsic_trunc(float %a) {
1413+
; CHECK-LABEL: name: test_intrinsic_trunc
1414+
; CHECK: [[A:%[0-9]+]]:_(s32) = COPY $s0
1415+
; CHECK: [[RES:%[0-9]+]]:_(s32) = G_INTRINSIC_TRUNC [[A]]
1416+
; CHECK: $s0 = COPY [[RES]]
1417+
%res = call float @llvm.trunc.f32(float %a)
1418+
ret float %res
1419+
}
1420+
1421+
declare float @llvm.round.f32(float)
1422+
define float @test_intrinsic_round(float %a) {
1423+
; CHECK-LABEL: name: test_intrinsic_round
1424+
; CHECK: [[A:%[0-9]+]]:_(s32) = COPY $s0
1425+
; CHECK: [[RES:%[0-9]+]]:_(s32) = G_INTRINSIC_ROUND [[A]]
1426+
; CHECK: $s0 = COPY [[RES]]
1427+
%res = call float @llvm.round.f32(float %a)
1428+
ret float %res
1429+
}
1430+
14111431
declare i32 @llvm.ctlz.i32(i32, i1)
14121432
define i32 @test_ctlz_intrinsic_zero_not_undef(i32 %a) {
14131433
; CHECK-LABEL: name: test_ctlz_intrinsic_zero_not_undef

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
# DEBUG-NEXT: G_BITCAST (opcode {{[0-9]+}}): 2 type indices
7979
# DEBUG: .. the first uncovered type index: 2, OK
8080
#
81+
# DEBUG-NEXT: G_INTRINSIC_TRUNC (opcode {{[0-9]+}}): 1 type index
82+
# DEBUG: .. type index coverage check SKIPPED: no rules defined
83+
#
84+
# DEBUG-NEXT: G_INTRINSIC_ROUND (opcode {{[0-9]+}}): 1 type index
85+
# DEBUG: .. type index coverage check SKIPPED: no rules defined
86+
#
8187
# DEBUG-NEXT: G_LOAD (opcode {{[0-9]+}}): 2 type indices
8288
# DEBUG: .. type index coverage check SKIPPED: user-defined predicate detected
8389
#

0 commit comments

Comments
 (0)