Skip to content

Commit 2b21c28

Browse files
authored
Add fneg handling to type analysis (rust-lang#947)
1 parent 10dfcf9 commit 2b21c28

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,22 @@ void TypeAnalyzer::visitValue(Value &val) {
11511151
if (!isa<Argument>(&val) && !isa<Instruction>(&val))
11521152
return;
11531153

1154+
#if LLVM_VERSION_MAJOR >= 10
1155+
if (auto *FPMO = dyn_cast<FPMathOperator>(&val)) {
1156+
if (FPMO->getOpcode() == Instruction::FNeg) {
1157+
Value *op = FPMO->getOperand(0);
1158+
auto ty = op->getType()->getScalarType();
1159+
assert(ty->isFloatingPointTy());
1160+
ConcreteType dt(ty);
1161+
updateAnalysis(op, TypeTree(ty).Only(-1, nullptr),
1162+
cast<Instruction>(&val));
1163+
updateAnalysis(FPMO, TypeTree(ty).Only(-1, nullptr),
1164+
cast<Instruction>(&val));
1165+
return;
1166+
}
1167+
}
1168+
#endif
1169+
11541170
if (auto inst = dyn_cast<Instruction>(&val)) {
11551171
visit(*inst);
11561172
}

enzyme/test/TypeAnalysis/fneg.ll

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: if [ %llvmver -ge 10 ]; then %opt < %s %loadEnzyme -print-type-analysis -type-analysis-func=caller -o /dev/null | FileCheck %s; fi
2+
3+
declare double @f()
4+
5+
define void @caller() {
6+
entry:
7+
%c = call double @f()
8+
%n = fneg double %c
9+
ret void
10+
}
11+
12+
; CHECK: caller - {} |
13+
; CHECK-NEXT: entry
14+
; CHECK-NEXT: %c = call double @f(): {[-1]:Float@double}
15+
; CHECK-NEXT: %n = fneg double %c: {[-1]:Float@double}
16+
; CHECK-NEXT: ret void: {}

0 commit comments

Comments
 (0)