[PATCH] D139321: InstCombine: Fix metadata arguments blocking freeze combining

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 05:41:56 PST 2022


arsenm created this revision.
arsenm added reviewers: nlopes, aqjune, jdoerfert.
Herald added a subscriber: hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a reviewer: sstefan1.
Herald added a project: LLVM.

These are used for special arguments to intrinsics and don't make any
sense to consider for poisonness. Fixes not pushing freeze through
llvm.fptrunc.round.

      

92106641ae297c24877085e0357e8095aa7b43c9 <https://reviews.llvm.org/rG92106641ae297c24877085e0357e8095aa7b43c9> made
isGuaranteedNotToBeUndefOrPoison return false for metadata arguments,
which doesn't entirely make sense. An alternate patch could switch
that to true, and try to filter out adding some pointless noundefs on
metadata arguments (I tried that, attributor breaks one case with a
llvm.dbg.value in it).


https://reviews.llvm.org/D139321

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/freeze-fp-ops.ll


Index: llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
===================================================================
--- llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
+++ llvm/test/Transforms/InstCombine/freeze-fp-ops.ll
@@ -508,9 +508,9 @@
 
 define float @freeze_fptrunc_round(double %arg0) {
 ; CHECK-LABEL: @freeze_fptrunc_round(
-; CHECK-NEXT:    [[OP:%.*]] = call float @llvm.fptrunc.round.f32.f64(double [[ARG0:%.*]], metadata !"round.downward")
-; CHECK-NEXT:    [[FREEZE:%.*]] = freeze float [[OP]]
-; CHECK-NEXT:    ret float [[FREEZE]]
+; CHECK-NEXT:    [[ARG0_FR:%.*]] = freeze double [[ARG0:%.*]]
+; CHECK-NEXT:    [[OP:%.*]] = call float @llvm.fptrunc.round.f32.f64(double [[ARG0_FR]], metadata !"round.downward")
+; CHECK-NEXT:    ret float [[OP]]
 ;
   %op = call float @llvm.fptrunc.round.f32.f64(double %arg0, metadata !"round.downward")
   %freeze = freeze float %op
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3803,7 +3803,8 @@
   // poison.
   Use *MaybePoisonOperand = nullptr;
   for (Use &U : OrigOpInst->operands()) {
-    if (isGuaranteedNotToBeUndefOrPoison(U.get()))
+    if (isa<MetadataAsValue>(U.get()) ||
+        isGuaranteedNotToBeUndefOrPoison(U.get()))
       continue;
     if (!MaybePoisonOperand)
       MaybePoisonOperand = &U;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139321.480079.patch
Type: text/x-patch
Size: 1494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221205/471ec930/attachment.bin>


More information about the llvm-commits mailing list