[llvm] [DirectX] Undo SimplifyCFG by reversing select into if else basic blocks (PR #153858)

Joshua Batista via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 16:26:52 PDT 2025


================
@@ -622,6 +625,92 @@ legalizeScalarLoadStoreOnArrays(Instruction &I,
   return true;
 }
 
+// Note: Legalization to undo SimplifyCFG. Ideally, SimplifyCFG's
+// TargetTransformInfo would ignore our resource intrinsics, but
+// it doesn't. This Works for a single select; multiple selects on
+// raw buffer loads won’t be legalized. The hasOneUser for ExtractValueInst
+// of dx_resource_load_rawbuffer is enforced in DXILOpLowering,
+// so checking it here is fine.
+static bool
+legalizeBuffLoadSelectCalls(Instruction &I,
+                            SmallVectorImpl<Instruction *> &ToRemove,
+                            DenseMap<Value *, Value *> &) {
+  // Check if this is a dx_resource_load_rawbuffer intrinsic
+  auto *II = dyn_cast<IntrinsicInst>(&I);
+  if (!II || II->getIntrinsicID() != Intrinsic::dx_resource_load_rawbuffer)
+    return false;
+
+  // Check if the first argument is a select instruction
+  Value *Arg0 = II->getArgOperand(0);
+  auto *Sel = dyn_cast<SelectInst>(Arg0);
+  if (!Sel)
+    return false;
+
+  if (!II->hasOneUser())
----------------
bob80905 wrote:

Why is this check necessary?

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


More information about the llvm-commits mailing list