[llvm] [InstCombine] Preserve metadata from orig load in select fold. (PR #115605)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 9 08:24:30 PST 2024


================
@@ -1065,6 +1065,25 @@ Instruction *InstCombinerImpl::visitLoadInst(LoadInst &LI) {
         V1->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
         V2->setAlignment(Alignment);
         V2->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
+        // Can copy any metadata that cannot trigger UB. In particular do not
+        // copy !noundef or !invariant.load.
+        unsigned SafeMDKinds[] = {LLVMContext::MD_dbg,
+                                  LLVMContext::MD_tbaa,
+                                  LLVMContext::MD_prof,
+                                  LLVMContext::MD_fpmath,
+                                  LLVMContext::MD_tbaa_struct,
+                                  LLVMContext::MD_alias_scope,
+                                  LLVMContext::MD_noalias,
+                                  LLVMContext::MD_nontemporal,
+                                  LLVMContext::MD_mem_parallel_loop_access,
+                                  LLVMContext::MD_access_group,
----------------
nikic wrote:

It's my understanding that we currently assume all AA-related metadata to be IUB. It's possible that we can relax some of it to return poison for loads and only be IUB, but if we want to do that, I'd expect this to start with a LangRef change. We should also keep https://github.com/llvm/llvm-project/blob/ccaded2b1d0d2cf3d8041baeeec9cfad632c9450/llvm/lib/IR/Instruction.cpp#L458-L468 in sync if we do that.

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


More information about the llvm-commits mailing list