[llvm] [InstCombine] Optimize addition of selects (PR #224477)

Tejas Joshi via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 26 16:21:11 PDT 2026


================
@@ -0,0 +1,25 @@
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+target datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64"
+
+; Test transform of:
+;   ((P == A ? X : Def) + Base) + (P == B ? Y : 0)
+; into:
+;   Base + (P == A ? X : (Def + (P == B ? Y : 0))
+define i32 @test_sum_selects(i32 %p, i32 %x, i32 %y, i32 %default, i32 %base) {
+; CHECK-LABEL: @test_sum_selects
+; CHECK-DAG: [[C0:%.*]] = icmp eq i32 %p, 288
+; CHECK-DAG: [[C1:%.*]] = icmp eq i32 %p, 128
----------------
Joshi-Tejas wrote:

Ping @boomanaiden154 @dtcxzyw 

https://github.com/llvm/llvm-project/pull/224477


More information about the llvm-commits mailing list