llvm.org GIT mirror llvm / 9b7f6f2
Instruction::isAssociative() returns true for fmul/fadd if they are tagged "unsafe" mode. Approved by: Eli and Michael. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168848 91177308-0d34-0410-b5e6-96231b3b80d8 Shuxin Yang 7 years ago
3 changed file(s) with 47 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
252252 ///
253253 /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
254254 ///
255 bool isAssociative() const { return isAssociative(getOpcode()); }
255 bool isAssociative() const;
256256 static bool isAssociative(unsigned op);
257257
258258 /// isCommutative - Return true if the instruction is commutative:
467467 Opcode == Add || Opcode == Mul;
468468 }
469469
470 bool Instruction::isAssociative() const {
471 unsigned Opcode = getOpcode();
472 if (isAssociative(Opcode))
473 return true;
474
475 switch (Opcode) {
476 case FMul:
477 case FAdd:
478 return cast(this)->hasUnsafeAlgebra();
479 default:
480 return false;
481 }
482 }
483
470484 /// isCommutative - Return true if the instruction is commutative:
471485 ///
472486 /// Commutative operators satisfy: (x op y) === (y op x)
0 ; RUN: opt < %s -instcombine -S | FileCheck %s
1
2 ; testing-case "float fold(float a) { return 1.2f * a * 2.3f; }"
3 ; 1.2f and 2.3f is supposed to be fold.
4 define float @fold(float %a) {
5 fold:
6 %mul = fmul fast float %a, 0x3FF3333340000000
7 %mul1 = fmul fast float %mul, 0x4002666660000000
8 ret float %mul1
9 ; CHECK: fold
10 ; CHECK: fmul float %a, 0x4006147AE0000000
11 }
12
13 ; Same testing-case as the one used in fold() except that the operators have
14 ; fixed FP mode.
15 define float @notfold(float %a) {
16 notfold:
17 ; CHECK: notfold
18 ; CHECK: %mul = fmul fast float %a, 0x3FF3333340000000
19 %mul = fmul fast float %a, 0x3FF3333340000000
20 %mul1 = fmul float %mul, 0x4002666660000000
21 ret float %mul1
22 }
23
24 define float @fold2(float %a) {
25 notfold2:
26 ; CHECK: fold2
27 ; CHECK: fmul float %a, 0x4006147AE0000000
28 %mul = fmul float %a, 0x3FF3333340000000
29 %mul1 = fmul fast float %mul, 0x4002666660000000
30 ret float %mul1
31 }