Skip to content

Commit

Permalink
GlobalISel: correctly handle trivial fcmp predicates.
Browse files Browse the repository at this point in the history
It makes sense to only do them once in IRTranslator rather than making everyone
deal with them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297304 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
TNorthover committed Mar 8, 2017
1 parent 773c83e commit f2856a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ bool IRTranslator::translateCompare(const User &U,
CmpInst::Predicate Pred =
CI ? CI->getPredicate() : static_cast<CmpInst::Predicate>(
cast<ConstantExpr>(U).getPredicate());

if (CmpInst::isIntPredicate(Pred))
MIRBuilder.buildICmp(Pred, Res, Op0, Op1);
else if (Pred == CmpInst::FCMP_FALSE)
MIRBuilder.buildConstant(Res, 0);
else if (Pred == CmpInst::FCMP_TRUE)
MIRBuilder.buildConstant(Res, 1);
else
MIRBuilder.buildFCmp(Pred, Res, Op0, Op1);

Expand Down
11 changes: 11 additions & 0 deletions test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,17 @@ define void @float_comparison(float* %a.addr, float* %b.addr, i1* %bool.addr) {
ret void
}

; CHECK-LABEL: name: trivial_float_comparison
; CHECK: [[R1:%[0-9]+]](s1) = G_CONSTANT i1 false
; CHECK: [[R2:%[0-9]+]](s1) = G_CONSTANT i1 true
; CHECK: G_ADD [[R1]], [[R2]]
define i1 @trivial_float_comparison(double %a, double %b) {
%r1 = fcmp false double %a, %b
%r2 = fcmp true double %a, %b
%sum = add i1 %r1, %r2
ret i1 %sum
}

@var = global i32 0

define i32* @test_global() {
Expand Down

0 comments on commit f2856a5

Please sign in to comment.