[llvm] [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (PR #85542)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 16 10:03:08 PDT 2024


================
@@ -1650,6 +1650,13 @@ static Value *foldOperationIntoSelectOperand(Instruction &I, SelectInst *SI,
                                              Value *NewOp, InstCombiner &IC) {
   Instruction *Clone = I.clone();
   Clone->replaceUsesOfWith(SI, NewOp);
+
+  // If we speculated an instruction, we need to drop any metadata that may
+  // result in undefined behavior, as the metadata might have been valid
+  // only given the branch precondition.
+  // Similarly strip attributes on call parameters that may cause UB in
+  // location the call is moved to.
----------------
nikic wrote:

Let's not copy this comment each time this method is called...

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


More information about the llvm-commits mailing list