diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-03-01 15:30:44 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-03-01 15:30:44 +0000 |
| commit | 3fd43a843b5e1c0671ee3736eb1e099737435ab5 (patch) | |
| tree | ce8bbbbf71ef66bf61350a2b1aa24f853998c98a | |
| parent | e75b42ee4ef0ed54d73a93c66f8bb9e9ed4e7006 (diff) | |
| download | bcm5719-llvm-3fd43a843b5e1c0671ee3736eb1e099737435ab5.tar.gz bcm5719-llvm-3fd43a843b5e1c0671ee3736eb1e099737435ab5.zip | |
[InstCombine] move/add tests for fmul reassociation; NFC
This transform may be out-of-scope for instcombine,
but this is only documenting the current behavior.
llvm-svn: 326442
| -rw-r--r-- | llvm/test/Transforms/InstCombine/fast-math.ll | 12 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/fmul.ll | 72 |
2 files changed, 72 insertions, 12 deletions
diff --git a/llvm/test/Transforms/InstCombine/fast-math.ll b/llvm/test/Transforms/InstCombine/fast-math.ll index 1843a784ab8..6c251c355cf 100644 --- a/llvm/test/Transforms/InstCombine/fast-math.ll +++ b/llvm/test/Transforms/InstCombine/fast-math.ll @@ -361,18 +361,6 @@ define float @fmul5(float %f1, float %f2) { ret float %t3 } -; (X*Y) * X => (X*X) * Y -define float @fmul6(float %f1, float %f2) { -; CHECK-LABEL: @fmul6( -; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[F1:%.*]], [[F1]] -; CHECK-NEXT: [[MUL1:%.*]] = fmul fast float [[TMP1]], [[F2:%.*]] -; CHECK-NEXT: ret float [[MUL1]] -; - %mul = fmul float %f1, %f2 - %mul1 = fmul fast float %mul, %f1 - ret float %mul1 -} - ; "(X*Y) * X => (X*X) * Y" is disabled if "X*Y" has multiple uses define float @fmul7(float %f1, float %f2) { ; CHECK-LABEL: @fmul7( diff --git a/llvm/test/Transforms/InstCombine/fmul.ll b/llvm/test/Transforms/InstCombine/fmul.ll index 34e0047946c..4c364f97d25 100644 --- a/llvm/test/Transforms/InstCombine/fmul.ll +++ b/llvm/test/Transforms/InstCombine/fmul.ll @@ -226,3 +226,75 @@ define float @fabs_x_fabs(float %x, float %y) { %mul = fmul float %x.fabs, %y.fabs ret float %mul } + +; (X*Y) * X => (X*X) * Y + +define float @reassoc_common_operand1(float %x, float %y) { +; CHECK-LABEL: @reassoc_common_operand1( +; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]] +; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]] +; CHECK-NEXT: ret float [[MUL2]] +; + %mul1 = fmul float %x, %y + %mul2 = fmul fast float %mul1, %x + ret float %mul2 +} + +; (Y*X) * X => (X*X) * Y + +define float @reassoc_common_operand2(float %x, float %y) { +; CHECK-LABEL: @reassoc_common_operand2( +; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X:%.*]], [[X]] +; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]] +; CHECK-NEXT: ret float [[MUL2]] +; + %mul1 = fmul float %y, %x + %mul2 = fmul fast float %mul1, %x + ret float %mul2 +} + +; X * (X*Y) => (X*X) * Y + +define float @reassoc_common_operand3(float %x1, float %y) { +; CHECK-LABEL: @reassoc_common_operand3( +; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00 +; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]] +; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]] +; CHECK-NEXT: ret float [[MUL2]] +; + %x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization + %mul1 = fmul float %x, %y + %mul2 = fmul fast float %x, %mul1 + ret float %mul2 +} + +; X * (Y*X) => (X*X) * Y + +define float @reassoc_common_operand4(float %x1, float %y) { +; CHECK-LABEL: @reassoc_common_operand4( +; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 3.000000e+00 +; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[X]] +; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[TMP1]], [[Y:%.*]] +; CHECK-NEXT: ret float [[MUL2]] +; + %x = fdiv float %x1, 3.0 ; thwart complexity-based canonicalization + %mul1 = fmul float %y, %x + %mul2 = fmul fast float %x, %mul1 + ret float %mul2 +} + +; No change if the first fmul has another use. + +define float @reassoc_common_operand_multi_use(float %x, float %y) { +; CHECK-LABEL: @reassoc_common_operand_multi_use( +; CHECK-NEXT: [[MUL1:%.*]] = fmul float [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[MUL1]], [[X]] +; CHECK-NEXT: call void @use_f32(float [[MUL1]]) +; CHECK-NEXT: ret float [[MUL2]] +; + %mul1 = fmul float %x, %y + %mul2 = fmul fast float %mul1, %x + call void @use_f32(float %mul1) + ret float %mul2 +} + |

