[llvm] 4af3960 - [InstCombine] Improve suboptimal simplification for more than one use in #190620 (#191702)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 12 06:14:31 PDT 2026


Author: Max Graey
Date: 2026-04-12T21:14:27+08:00
New Revision: 4af396057caf2df49df8d3f60f0ae040ae9312b4

URL: https://github.com/llvm/llvm-project/commit/4af396057caf2df49df8d3f60f0ae040ae9312b4
DIFF: https://github.com/llvm/llvm-project/commit/4af396057caf2df49df8d3f60f0ae040ae9312b4.diff

LOG: [InstCombine] Improve suboptimal simplification for more than one use in #190620 (#191702)

Address to
https://github.com/llvm/llvm-project/pull/190620#issuecomment-4229926121

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/test/Transforms/InstCombine/fp-floor-ceil.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9cb7a4ec61903..362bd663434df 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -8782,7 +8782,7 @@ static Instruction *foldFCmpWithFloorAndCeil(FCmpInst &I,
     }
   }
 
-  if ((FloorX || CeilX) && FCmpInst::isCommutative(Pred)) {
+  if ((FloorX || CeilX) && FCmpInst::isCommutative(Pred) && LHS->hasOneUse()) {
     // fcmp pred floor(x), x => fcmp pred trunc(x), x
     // fcmp pred  ceil(x), x => fcmp pred trunc(x), x
     // where pred is oeq, one, ord, ueq, une, uno.

diff  --git a/llvm/test/Transforms/InstCombine/fp-floor-ceil.ll b/llvm/test/Transforms/InstCombine/fp-floor-ceil.ll
index 6a0181c369ca9..0a32d38851206 100644
--- a/llvm/test/Transforms/InstCombine/fp-floor-ceil.ll
+++ b/llvm/test/Transforms/InstCombine/fp-floor-ceil.ll
@@ -382,3 +382,29 @@ define i1 @x_ceil_false_neg(float %x) {
   %ret = fcmp false float %x, %ceil
   ret i1 %ret
 }
+
+define float @x_floor_more_one_use_neg(float %x) {
+; CHECK-LABEL: @x_floor_more_one_use_neg(
+; CHECK-NEXT:    [[FLOOR:%.*]] = call float @llvm.floor.f32(float [[X:%.*]])
+; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq float [[FLOOR]], [[X]]
+; CHECK-NEXT:    [[RET:%.*]] = select i1 [[CMP]], float 0.000000e+00, float [[FLOOR]]
+; CHECK-NEXT:    ret float [[RET]]
+;
+  %floor = call float @llvm.floor.f32(float %x)
+  %cmp = fcmp oeq float %floor, %x
+  %ret = select i1 %cmp, float 0.0, float %floor
+  ret float %ret
+}
+
+define float @x_ceil_more_one_use_neg(float %x) {
+; CHECK-LABEL: @x_ceil_more_one_use_neg(
+; CHECK-NEXT:    [[CEIL:%.*]] = call float @llvm.ceil.f32(float [[X:%.*]])
+; CHECK-NEXT:    [[CMP:%.*]] = fcmp une float [[CEIL]], [[X]]
+; CHECK-NEXT:    [[RET:%.*]] = select i1 [[CMP]], float [[CEIL]], float 0.000000e+00
+; CHECK-NEXT:    ret float [[RET]]
+;
+  %ceil = call float @llvm.ceil.f32(float %x)
+  %cmp = fcmp une float %ceil, %x
+  %ret = select i1 %cmp, float %ceil, float 0.0
+  ret float %ret
+}


        


More information about the llvm-commits mailing list