@@ -514,3 +514,40 @@ of operands.
514
514
(match (does_not_bind $tmp, $x)
515
515
(G_MUL $dst, $x, $tmp)),
516
516
(apply (COPY $dst, $x))>;
517
+
518
+
519
+
520
+
521
+ Gallery
522
+ =======
523
+
524
+ We should use precise patterns that state our intentions. Please avoid
525
+ using wip_match_opcode in patterns.
526
+
527
+ .. code-block :: text
528
+ :caption: Example fold zext(trunc:nuw)
529
+
530
+ // Imprecise: matches any G_ZEXT
531
+ def zext : GICombineRule<
532
+ (defs root:$root),
533
+ (match (wip_match_opcode G_ZEXT):$root,
534
+ [{ return Helper.matchZextOfTrunc(*${root}, ${matchinfo}); }]),
535
+ (apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
536
+
537
+
538
+ // Imprecise: matches G_ZEXT of G_TRUNC
539
+ def zext_of_trunc : GICombineRule<
540
+ (defs root:$root),
541
+ (match (G_TRUNC $src, $x),
542
+ (G_ZEXT $root, $src),
543
+ [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
544
+ (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
545
+
546
+
547
+ // Precise: matches G_ZEXT of G_TRUNC with nuw flag
548
+ def zext_of_trunc_nuw : GICombineRule<
549
+ (defs root:$root),
550
+ (match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
551
+ (G_ZEXT $root, $src),
552
+ [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
553
+ (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
0 commit comments