@@ -341,3 +341,52 @@ define double @fdiv_pow_powi_negative_variable(double %x, i32 %y) {
341
341
%div = fdiv reassoc nnan double %p1 , %x
342
342
ret double %div
343
343
}
344
+
345
+ ; powi(X, Y) * X --> powi(X, Y+1)
346
+ define double @powi_fmul_powi_x (double noundef %x ) {
347
+ ; CHECK-LABEL: @powi_fmul_powi_x(
348
+ ; CHECK-NEXT: [[MUL:%.*]] = call reassoc double @llvm.powi.f64.i32(double [[X:%.*]], i32 4)
349
+ ; CHECK-NEXT: ret double [[MUL]]
350
+ ;
351
+ %p1 = tail call double @llvm.powi.f64.i32 (double %x , i32 3 )
352
+ %mul = fmul reassoc double %p1 , %x
353
+ ret double %mul
354
+ }
355
+
356
+ ; Negative test: Multi-use
357
+ define double @powi_fmul_powi_x_multi_use (double noundef %x ) {
358
+ ; CHECK-LABEL: @powi_fmul_powi_x_multi_use(
359
+ ; CHECK-NEXT: [[P1:%.*]] = tail call double @llvm.powi.f64.i32(double [[X:%.*]], i32 3)
360
+ ; CHECK-NEXT: tail call void @use(double [[P1]])
361
+ ; CHECK-NEXT: [[MUL:%.*]] = fmul reassoc double [[P1]], [[X]]
362
+ ; CHECK-NEXT: ret double [[MUL]]
363
+ ;
364
+ %p1 = tail call double @llvm.powi.f64.i32 (double %x , i32 3 )
365
+ tail call void @use (double %p1 )
366
+ %mul = fmul reassoc double %p1 , %x
367
+ ret double %mul
368
+ }
369
+
370
+ ; Negative test: Miss fmf flag
371
+ define double @powi_fmul_powi_x_missing_reassoc (double noundef %x ) {
372
+ ; CHECK-LABEL: @powi_fmul_powi_x_missing_reassoc(
373
+ ; CHECK-NEXT: [[P1:%.*]] = tail call double @llvm.powi.f64.i32(double [[X:%.*]], i32 3)
374
+ ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[P1]], [[X]]
375
+ ; CHECK-NEXT: ret double [[MUL]]
376
+ ;
377
+ %p1 = tail call double @llvm.powi.f64.i32 (double %x , i32 3 )
378
+ %mul = fmul double %p1 , %x
379
+ ret double %mul
380
+ }
381
+
382
+ ; Negative test: overflow
383
+ define double @powi_fmul_powi_x_overflow (double noundef %x ) {
384
+ ; CHECK-LABEL: @powi_fmul_powi_x_overflow(
385
+ ; CHECK-NEXT: [[P1:%.*]] = tail call double @llvm.powi.f64.i32(double [[X:%.*]], i32 2147483647)
386
+ ; CHECK-NEXT: [[MUL:%.*]] = fmul reassoc double [[P1]], [[X]]
387
+ ; CHECK-NEXT: ret double [[MUL]]
388
+ ;
389
+ %p1 = tail call double @llvm.powi.f64.i32 (double %x , i32 2147483647 ) ; INT_MAX
390
+ %mul = fmul reassoc double %p1 , %x
391
+ ret double %mul
392
+ }
0 commit comments