[llvm] r326606 - [InstCombine] add tests for rL169025; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 2 11:26:13 PST 2018
Author: spatel
Date: Fri Mar 2 11:26:13 2018
New Revision: 326606
URL: http://llvm.org/viewvc/llvm-project?rev=326606&view=rev
Log:
[InstCombine] add tests for rL169025; NFC
This narrow fold was added with no motivation or test cases
a bit over 5 years ago. Removing a constant operand is a
good canonicalization? We should handle Y*2.0 too then?
Modified:
llvm/trunk/test/Transforms/InstCombine/fmul.ll
Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul.ll?rev=326606&r1=326605&r2=326606&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Fri Mar 2 11:26:13 2018
@@ -300,3 +300,35 @@ define float @reassoc_common_operand_mul
ret float %mul2
}
+declare float @llvm.log2.f32(float)
+
+; X * log2(Y * 0.5) = X * log2(Y) - X
+
+define float @log2half(float %x, float %y) {
+; CHECK-LABEL: @log2half(
+; CHECK-NEXT: [[LOG2:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[LOG2]], [[X:%.*]]
+; CHECK-NEXT: [[MUL:%.*]] = fsub fast float [[TMP1]], [[X]]
+; CHECK-NEXT: ret float [[MUL]]
+;
+ %halfy = fmul fast float %y, 0.5
+ %log2 = call fast float @llvm.log2.f32(float %halfy)
+ %mul = fmul fast float %log2, %x
+ ret float %mul
+}
+
+define float @log2half_commute(float %x1, float %y) {
+; CHECK-LABEL: @log2half_commute(
+; CHECK-NEXT: [[X:%.*]] = fdiv float [[X1:%.*]], 7.000000e+00
+; CHECK-NEXT: [[LOG2:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[X]], [[LOG2]]
+; CHECK-NEXT: [[MUL:%.*]] = fsub fast float [[TMP1]], [[X]]
+; CHECK-NEXT: ret float [[MUL]]
+;
+ %x = fdiv float %x1, 7.0 ; thwart complexity-based canonicalization
+ %halfy = fmul fast float %y, 0.5
+ %log2 = call fast float @llvm.log2.f32(float %halfy)
+ %mul = fmul fast float %x, %log2
+ ret float %mul
+}
+
More information about the llvm-commits
mailing list