[llvm] [DirectX] Undo SimplifyCFG by reversing select into if else basic blocks (PR #153858)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 15 19:41:54 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())
----------------
farzonl wrote:
`replaceResRetUses` requires that `ExtractValueInst` be the only use.
https://github.com/llvm/llvm-project/blob/76d993bd25ff462d915f69772454e7b1ca42fdb8/llvm/lib/Target/DirectX/DXILOpLowering.cpp#L368-L370
https://github.com/llvm/llvm-project/pull/153858
More information about the llvm-commits
mailing list